- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:05 AM
Hi I have done a very simple workflow which I am trigger using a business rule. Please find below my business rule, workflow.
Business rule:
(function executeRule(current, previous /*null when async*/)
{
.........................
...........................
..........................
var gr = new GlideRecord('wf_workflow');
gr.addQuery('name', 'Z');
gr.query();
if (gr.next()) {
var wf = new Workflow();
var workflowId = '' + gr.sys_id;
var vars = {};
vars.number =5;
wf.startFlow(workflowId, current, current.operation, {number: 5});
}
action.setRedirectURL(current);
})(current, previous);
My aim is to assign a value to a workflow variable. Here if workflow variable which i have named as number =5 i need to get mail with subject YES or else NO. Code in If block of workflow is
answer = ifScript();
function ifScript() {
if (workflow.scratchpad.number==5) {
return 'yes';
}
return 'no';
}
Problem is it is always giving NO message. Can anybody help me to get this concept..
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 09:58 PM
Hi Naman,
Yes its the right method.
Whats the column name. check if you are using the same in your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 06:25 AM
Hi Naman,
Try using
Reading the Value of a Workflow Input Variable
The value of a Workflow input variable is accessible anywhere within the workflow that accepts javascript by dot walking the current workflow object:
var readValue = workflow.inputs.variable_name;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 11:59 AM
I tried this , still getting NO in the mail. I eanted to know how to check whether variable number is assigned with a value? Is this working or no [ wf.startFlow(workflowId, current, current.operation, {number: 5});]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 12:02 PM
it should be like this :
var wf = new Workflow();
var workflowId = '' + gr.sys_id;
var vars = {};
vars.number =5;
wf.startFlow(workflowId, current, current.operation() , vars);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 12:10 PM
Hello Naman,
I don't see any issue in your code. Please refer sample ex section 4 for more info.
Using Variables in a Workflow - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 09:47 PM