passing a variable to the workflow from a business rule does not work

DoDo labs___
Mega Sage

Hi,

 

I am trying to pass a variable from business rule to workflow, but it does not receive it.

 

This is the business rule:


(function executeRule(current, previous /*null when async*/) {

var u_vars = {};

u_vars.u_met = 'Test 2';

var w = new Workflow();
var context = w.startFlow('ea52870687239e10d111646e8bbb357d', current, current.operation(), u_vars);

})(current, previous);

 

 

This is the workflow input:

 

DoDolabs____0-1739092727339.png

 

 

And here is the workflow script:

 

var input = workflow.variables.u_vars;

var testing = new GlideRecord('incident');
testing.addQuery('number', 'INC0295583');
testing.query();
if (testing.next())
{
testing.comments = 'TEST 1';
testing.comments = input.u_met;
testing.update();
}

 

 

The workflow runs, since the TEST 1 comment is appear in the incident, but the test 2 value is not received.

DoDolabs____1-1739092868386.png

 

1 ACCEPTED SOLUTION

"Test 2" appeared in the log, so the workflow received the value. From this I realized that toString() should be used:
var inputValue = workflow.inputs.u_met.toString();

 

Finally the value appeared in the incident as well.

 


Business rule:

(function executeRule(current, previous /*null when async*/) {


var vars = {};
vars.u_met = 'Test 2';

var w = new Workflow();
var context = w.startFlow('ea52870687239e10d111646e8bbb357d', '', 'FIG_ignored_emails', vars);

})(current, previous);


Workflow inputs:

Type: String
Label: Email Sys ID
Column name: u_met
Max length: 60


Workflow script:

var inputValue = workflow.inputs.u_met.toString();

var testing = new GlideRecord('incident');
testing.addQuery('number', 'INC0295583');
testing.query();
if (testing.next())
{
testing.comments = inputValue ;
testing.update();
}

 


Thank you all for your help!

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@DoDo labs___ 

I hope business rule and workflow are in same scope

(function executeRule(current, previous /*null when async*/) {

var obj = {};
obj.u_met = 'Test 2';
var w = new Workflow();
var context = w.startFlow('ea52870687239e10d111646e8bbb357d', current, current.operation(), obj);

})(current, previous);

correct way to get the value is this

var input = workflow.inputs.u_vars; // don't use workflow.variables

var testing = new GlideRecord('incident');
testing.addQuery('number', 'INC0295583');
testing.query();
if (testing.next())
{
testing.comments = 'TEST 1';
testing.comments = input.u_met;
testing.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, it is the same scope, but still but still only "TEST 1" is appear 😞

@DoDo labs___ 

same has worked in the past as per my solution

Trouble Accessing variables from inbound action 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Viraj Hudlikar
Tera Sage

Hello @DoDo labs___ 

 

Check this thread 

Solved: Need to call a workflow from the business rule and... - ServiceNow Community

Using variables in a workflow

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.