
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 02:09 PM
I have a basic scheduled job that kicks off a workflow.
I want to be able to pass the value of a variable to the workflow and use it within the workflow.
Here is the scheduled job that is intended to pass the value (currently it is just a hard-coded string for testing). Once this is working it will be an onchange client script via glideajax that will pass the value of the catalog item variable.
var gr = new GlideRecord('wf_workflow');
gr.addQuery('name', 'Hostname Check if Taken');
gr.query();
if (gr.next()) {
var wf = new Workflow();
var workflowId = '' + gr.sys_id;
var vars = {u_hostname: "hostname123"};
wf.startFlow(workflowId, current, current.operation, vars);
}
Then within the workflow there is a "Run Script" activity that sets the variable to the scratchpad and should print the value to the log. However the log shows that the variable is undefined. It should be as that hard-coded string "hostname123"
workflow.scratchpad.u_hostname = current.variables.u_hostname;
var hostname = workflow.scratchpad.u_hostname;
gs.log(hostname);
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 10:49 PM
I think you also need to configure this variable in workflow inputs and then the variable will be accessible using workflow.inputs.variable_name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 08:42 AM
Thank you! I can send the value to the workflow as an input value. I am now trying to get the result of the workflow BACK on the client side before the form is submitted if that is possible.
Run Workflow from Client Script then retrieve value BACK before submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 05:19 AM
HI Katie,
Could you please share the piece of code like how you are able to fetch the variables from script into the workflow.
I tried however it says undefined in the log.
Thanks,
Akram
script:
var wf = new Workflow();
var wfId = wf. getWorkflowFromName ( "Scheduling Deprovision for ContEmp" ) ;
var vars={};
requestsys_id=createRequest.sys_id.toString();
vars.test="sampledata";
wf.startFlow(wfId, conEmp, conEmp.operation(), vars);
workflow:
var test1=workflow.inputs.test;
gs.info("test for auto call in workflow "+test1);
I am trying to get the 'vars.test' value in workflow.