Setting and accessing workflow variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 09:12 PM
I have been trying to grok this all day and I'm at my wit's end. I feel like I'm missing something really simple. I'm trying to set and access workflow variables from a business rule. Here's what I've done.
I created a test workflow in my personal instance called "Test Workflow". I edited the inputs on that workflow to add a string variable called TestVar [u_testvar], and I set the default value of it to "Init test".
Now I've plopped a Run Script workflow activity in the workflow that accesses this variable and prints it out to the script log. I'm trying to access it by both workflow.variables and workflow.inputs, because to be honest, I'm still not really sure what the difference between those two things are.
Here's my script:
gs.log('--->Access [1]: ' + workflow.variables.u_testvar);
gs.log('--->Access [2]: ' + workflow.inputs.u_testvar);
I fire off the workflow, and in my script log I see:
So far, so good. But let's say that in my script I want to change the value of the variable. I've added some more lines, throwing in the kitchen sink, trying to account for all ways of setting this variable. Now it is as follows:
gs.log('--->Access [1]: ' + workflow.variables.u_testvar);
gs.log('--->Access [2]: ' + workflow.inputs.u_testvar);
workflow.variables.u_testvar = 'Modify Variables Test [1]';
gs.log('--->Access [3]: ' + workflow.variables.u_testvar);
workflow.update();
gs.log('--->Access [4]: ' + workflow.variables.u_testvar);
workflow.inputs.u_testvar = 'Modify Inputs Test [1]';
gs.log('--->Access [5]: ' + workflow.inputs.u_testvar);
workflow.update();
gs.log('--->Access [6]: ' + workflow.inputs.u_testvar);
Again, I fire off the workflow, and this is my script log:
...!!?
Nothing I did in the Run Script activity had any affect on the workflow variable.
Okay, well, let me try finding this thing via a background script, so that I can eventually put it in a business rule.
var grRequest = new GlideRecord('sc_request');
if (!grRequest.get('number', 'REQ0010002'))
gs.print('Cannot find request');
var msg = '--->Looking for workflow variables in ' + grRequest.number + "\n";
msg += ' Using variables: ' + grRequest.variables.u_testvar + "\n";
msg += ' Using inputs: ' + grRequest.inputs.u_testvar + "\n";
gs.log(msg);
From my script log:
Nothing. Nothing I do can seem to access these variables. The best I've been able to achieve so far is reading the default value from inside a script. What gives? How do I set variables in workflow scripts? How can I read and write them from a business rule?
And before you refer me to this article, please understand that I have read it a dozen times. It tells me how to read a variable, but not to write to it, and certainly not how to access it in a business rule. And before you refer me to this article, I've read it a dozen times also. It explains how I can write the variables when I start the workflow from a script, but not after that time.
Help?
Thanks,
--Dennis R
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 10:28 PM
Hi Dennis,
Why would you want to read the workflow variables from a business rule? As long as the workflow is running you have all the possibilities to make any changes you want inside the instance of the workflow and when the workflow has finished you should have perfomed any actions you require.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 04:25 AM
Because I have another task that I want to cause the workflow to advance past a "Wait for condition". Ultimately, I'm trying to implement a general-purpose serial workflow in which completion of one task triggers another, and I was trying to accomplish that by creating a business rule on the request items that sets a variable on a workflow to alert it that the task is completed.
I've posted a much longer discussion about it here, and I'm still trying to suss this out. I still haven't made any headway on either problem:
Creating tasks in series such that completion of one triggers creation of another
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2018 07:14 AM
Hi Denis,
You got the solution for this, workflow edit input variables. How to pass the values to this and get the parent workflow.
Thanks,
Mukund