01-19-2024 12:56 PM
Hi,
I am wondering if I can create a global variable in a workflow that can be shared/updated between the different device instances during a script activity. I created a variable, and I made it's scope "WORKFLOW":
but it seems that if I manipulate this variable within a "script activity" in different device instances, it's not really global in that sense if I have multi devices running; I find that for the "script activity" every device has it's own until the activity is done then it it just takes the last device.
Not sure if I am making myself clear, but I want to be able to manipulate a variable (add entries to it) from the same script activity for different devices.
Thanks,
Solved! Go to Solution.
01-23-2024 07:19 AM
If 10 devices get executed each activity has per device the own thread to run in parallels. If all writing to the same global variable the last wan will win.
The alternative I explained is more complicated to set and relay on the activity ID, but it makes sure that each thread (device) gets its data shared.
Also, you can consider using the device annotation to store data per device. Or using site variables depends on what you like to achieve.
write device annotation
mutation {
network {
configureDevice(input: {
deviceConfig: {
ipAddress: "192.168.0.11"
deviceAnnotationConfig: {
userData1: "my stuff"
}
}
}) {
message
status
}
}
}
read device annotation
{
network {
device(ip: "192.168.0.11") {
deviceData {
userData1
}
}
}
}
01-22-2024 01:34 AM
Alternatively you can use the activity variables.
01-22-2024 01:33 AM
01-22-2024 07:02 AM
Hi,
Thanks. You said in your second reply. There would be conflict and last one will win. My activity runs for each device the user has selected (say they multiselected 10 devices and ran the workflow). Then the activity will run for each device. Let's say the outcome of each activity run is that some devices were changed, and thus needs a save config, and some didn't change and thus don't need a save config. So I was trying to add the devices that need to have config saved into one list so at the end I can save config for them, or report those devices in an event. But because I don't really have a global variable that I can use between device activities, then I am stuck to save config for all of them.
Not sure how your first reply on having a variable scoped per activity will help me solve the global variable question.
Thanks,
01-23-2024 07:19 AM
If 10 devices get executed each activity has per device the own thread to run in parallels. If all writing to the same global variable the last wan will win.
The alternative I explained is more complicated to set and relay on the activity ID, but it makes sure that each thread (device) gets its data shared.
Also, you can consider using the device annotation to store data per device. Or using site variables depends on what you like to achieve.
write device annotation
mutation {
network {
configureDevice(input: {
deviceConfig: {
ipAddress: "192.168.0.11"
deviceAnnotationConfig: {
userData1: "my stuff"
}
}
}) {
message
status
}
}
}
read device annotation
{
network {
device(ip: "192.168.0.11") {
deviceData {
userData1
}
}
}
}