- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 01:59 AM
Hi Team,
Can somebody help me on this.
i am trying to copy values from variables(which are in Variable set) to fields in RITM Table by using Business rule.
By using below script in my after business rule which is on the sc_req_item table values are not copied.
(function executeRule(current, previous /*null when async*/) {
// Note: if i am using if condition like this values are NOT Copied. and if i remove if condition values are copied.
if((current.variables.standard_employee_questions.check_this_box=='true')&&(current.variables.standard_employee_questions.needed_by=='today')){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
current.update();
}}
)(current, previous);
Please let me know how to resolve this? and i can't use run script activity in workflow as my variable set is used in multiple catalog items and they have different workflows. i don't want to modify all the workflows.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 03:04 AM
This works fine with a before Insert Business Rule. When referring to variables in a workflow or BR script, use the syntax current.variables.variable_name, not current.variables.variable_set_name.variable_name, so this script will work.
(function executeRule(current, previous /*null when async*/) {
if(current.variables.check_this_box.toString() =='true' && current.variables.needed_by == 'today'){
current.u_requestor = current.variables.requested_for;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 02:03 AM
Hi,
yes you can use workflow run script if you already have catalog item workflow
script would be like this
if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
}
OR
you can also use before insert BR on sc_req_item table with proper condition so that it runs only for your catalog item's RITM
(function executeRule(current, previous /*null when async*/) {
if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 02:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 02:53 AM
then make that BR as After Insert and update as this
(function executeRule(current, previous /*null when async*/) {
if(current.variables.standard_employee_questions.check_this_box.toString() =='true' && current.variables.standard_employee_questions.needed_by == 'today'){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
current.setWorkflow(false);
current.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 03:22 AM
Hi,
the actual syntax for accessing any variable be it within variable set or outside variable set is the same
current.variables.variableName
So try this once as mentioned by Brad in before insert BR and it should work fine
(function executeRule(current, previous /*null when async*/) {
if(current.variables.check_this_box.toString() =='true' && current.variables.needed_by.toString() == 'today'){
current.u_requestor = current.variables.standard_employee_questions.requested_for;
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader