cancel
Showing results for 
Search instead for 
Did you mean: 

global variable when running a multidevice workflow

global variable when running a multidevice workflow

Chad5
Contributor

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":

Chad5_0-1705697590813.png

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,

1 ACCEPTED SOLUTION

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
      }
    }
  }
}

 

 

 

View solution in original post

5 REPLIES 5

Markus_Nikulski
Extreme Employee

Alternatively you can use the activity variables.

Markus_Nikulski_1-1705916066416.png

 

Markus_Nikulski
Extreme Employee

Markus_Nikulski_0-1705915943489.png

 

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,

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
      }
    }
  }
}

 

 

 

GTM-P2G8KFN