Setting, or updating variables in flow designer

Derek C
Tera Guru

Hi all,

I'm trying to update a variable on a task (or ritm) from within a flow in flow designer. What I have done is:

1. Create a custom action called "update TASK variable"

2. created three inputs, one reference type called task that references the sc_task table, one string type called variable, another string type called new value

3. run a simple script to update the variable typed in the inputs

(function execute(inputs, outputs) {
  
  var task = new GlideRecord('sc_task');
  task.get(inputs.task.getUniqueValue());
  task.variables.inputs.variable = inputs.newValue;
  task.update();

  
})(inputs, outputs);

This does not work because you can not use the inputs.variable in the line "task.variable.inputs.variable = inputs.newValue", I also tried "task.variables. + inputs.variable = inputs.newValue" but that does not work either. If I hard code it like "task.variables.approver_instructions = inputs.newValue" that works. I'd rather this action be re-usable for many flows, so I'd rather not hard code it as that makes it limited to a small scope of flows.

Is it possible to pass in a value in the inputs variables and dynamically set variables like this? Or am I out luck here.

Any thoughts / ideas / suggestions are appreciated!

Thanks!

- Derek

1 ACCEPTED SOLUTION

Thanks for the reply, I have had the joy of figuring out the complicated way variables are saved in the past so fortunately what you're saying makes sense.

I didn't want to do it this way, but what I ended up doing is (bonus it's no code!)

1. do a look up record on the sc_item_option_mtom table where "Parent Item" is the RITM (use data pill). Optional AND "Dependent Item.Question.Name" IS ${name value}

2. another look up record on the sc_item_option table where "sys_id" is "Dependent Item.sys_id" of the record found in step 1.

 

That will return the sc_item_option record with the value of the variable that needs to be updated and can be used through the rest of the flow.

Not ideal, but works and is no code. 

I really wish they'd have an OOB action item to update variables, maybe in a future release.

Thanks,

- Derek

View solution in original post

10 REPLIES 10

Jan K_lb_k
Tera Contributor

Hi Derek.

You can create your reusable action, which sets a variable based on inputs like this:

(function execute(inputs, outputs) {
  inputs.record.variables[inputs.variable] = inputs.value;
  inputs.record.update();
})(inputs, outputs);

Where record, variable and value are inputs to the action. Record should be set to a reference, while the other two variables are strings.

Best regards, Jan