system.sfc.setVariable
Sets a variable inside a currently running chart.
system.sfc.setVariable(instanceId, [stepId], variableName, variableValue)
-
Parameters
String instanceId - The instance identifier of the chart.
String stepId - [Optional] The id for a step inside of a chart. If omitted the function will target a chart scoped variable.
String variableName - The name of the variable to set.
Object variableValue - The value for the variable to be set to.
-
Returns
Nothing
-
Scope
All
Omitting the stepId parameter will cause the function to target a chart scoped variable. If the variable is persistent to the whole chart, or used in multiple different steps, then this parameter should be omitted.
If a stepId parameter is used, then the function will target a step scoped variable. The step associated with the stepId must be the currently active step.
#The following passes the chart instance ID and step ID to a client message Handler. The message handler can then wait #for user input, and then write back to the step variables. #The example assumes there is a chart scoped variable called confirmEndchart, and a step scoped variable called "messageSent". #Get the instanceId of the current chartchartID = chart.get("instanceId") #Get the id of the stepstepID = step.get("id") #Create a payload to pass to the client.#Include the instanceId and stepId so the script from the message handler knows which#chart and step to write topayload = {"chartID" : chartID, "stepID" : stepID} #Send the messagesystem.util.sendMessage(project = "SFC", messageHandler = "SFCMessage", payload = payload ############ #The following script would be placed on a client message handler. This receives the payload, #and sets a variable on either the chart or step depending on user selection#Read items out of the payloadid = payload['chartID']stepId = payload['stepID'] #Ask the user to end the chartif system.gui.confirm("Would you like to end the process"): #If yes, end the chart. confirmEndChart is chart scoped, so only 3 parameters are passed system.sfc.setVariable(id,"confirmEndChart",True)else: #If no, reset the step.messageSent variable so that the user will be prompted again #messageSent is step scoped, so 4 parameters are passed system.sfc.setVariable(id,stepId,"messageSent",False)