- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2016 01:04 PM
I'm trying to pass variables from a record producer to a workflow that I'm kicking off via the script. Here is the script I'm running. (function() { current.short_description = "CCS Release " + producer.name; var vars = getVars(); gs.log("vars.application" + vars.application, "jjw"); var w = new Workflow(); var wfSysId = w.getWorkflowFromName("CCS Release"); w.startFlow(wfSysId, current, current.operation(), vars); })(); function getVars() { var vars = {}; for (var n in producer){ vars[n] = producer[n]; } return vars; } When this runs I do get the log message displaying a sys_id for the application from the record producer. However when I log out current.variables.application or workflow.variables.application in the workflow I get undefined. It seems that my variables are not getting passed into the workflow at all.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2016 03:15 AM
Ah. I see. From my tests I can definitely see that current is not available to the Workflow from a Record Producer, so you cannot use current.variables.variablename. I suspect that this behaviour is by design. Though it would be good to get an Incident logged with Technical Support for confirmation so that the documentation can be revised or Problem logged.
Nevertheless, you can refer to the Article that Anurag provided. I achieved this on my demo using the OOB Create Incident Record Producer.
- Created a Test Workflow that has a Run Script activity.
- Add the following line to the script
gs.log("workflow.variables.u_comments: " + workflow.variables.u_comments);
- Edit the Inputs for the Workflow and added a variable called comments (it will get automatically renamed to u_comments) with the same config as the comments variable on the Record Producer
- In my Record Producer I added the following script
var wf = new Workflow();
var wfId = wf.getWorkflowFromName("WorkflowInputTest");
var variableArr = {};
variableArr.u_comments = producer.comments;
wf.startFlow(wfId, null, "WorkflowInputTest", variableArr);
When reviewing the logs I do see the output:
*** Script: workflow.variables.u_comments: testing2
The part of the Wiki article that led me to this is here: Using Variables in a Workflow - ServiceNow Wiki (Geneva: Workflow input variables)
I hope that this helps
EDIT: Adding link to Geneva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2016 07:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2016 07:45 AM
That worked my issue was in assuming that the inputs would get created for me. After I created them on the workflow and assigned the values individually I was able to use them in the workflow via workflow.variables.<input name>
Thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2018 01:05 AM
Hi John,
Could you please mention in detail about how u achieved it?
I 'm stuck in a similar problem...But i do not know the syntax of how create the variables on the workflow
Thanks and regards
Lynette
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2018 05:42 AM
I used these.
https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/task/t_WorkflowInputVariables.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2017 05:13 PM
I was just able to use current.[variable name] since it was incident create that spun the workflow off in the 1st place -