- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 01:26 AM
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:
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 04:33 AM
"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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 02:34 AM
Hello,
Unfortunately the url (https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/task... inside the solution is not found.
And what should I write in the workflow input?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 03:22 AM
@DoDo labs___ - Did you follow my previous response where you need to change input variable name?
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 02:46 AM
Hello @DoDo labs___
First declare input variable properly as you passing value in u_met in your BR so it will be as below
BR script:
(function executeRule(current, previous /*null when async*/) {
var vars = {};
vars.u_met = 'Test 2';
var w = new Workflow();
var wfId = wflow.getWorkflowFromName("Provide Your Workflow Name"); //using this will be best as if wf is checkout and publish sometimes we tend to forget to update sys_id
var context = w.startFlow(wfId, current, current.operation(), vars);
})(current, previous);
Then in your workflow script will be as below:
var inputValue = workflow.inputs.u_met;
var testing = new GlideRecord('incident');
testing.addQuery('number', 'INC0295583');
testing.query();
if (testing.next())
{
testing.comments = inputValue ;
testing.update();
}
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 03:41 AM
There is no new comment in the incident 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 03:45 AM - edited 02-09-2025 03:45 AM
@DoDo labs___ - Can you try adding logs in workflow script activity where you are receiving input value and see what value you are receiving?