pass variables to workflow

John Warren
Kilo Guru

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.

1 ACCEPTED SOLUTION

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.


  1. Created a Test Workflow that has a Run Script activity.
  2. Add the following line to the script
    gs.log("workflow.variables.u_comments: " + workflow.variables.u_comments);
  3. 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
  4. 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


View solution in original post

9 REPLIES 9

John Warren
Kilo Guru

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.


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  

I used these.

 

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/task/t_WorkflowInputVariables.html

skylarbarth
Kilo Expert

I was just able to use current.[variable name] since it was incident create that spun the workflow off in the 1st place -