
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 02:06 PM
I am new to scripting, but I just completed the Scripting in ServiceNow Fundamentals class and I am trying to put some of what I learned to work. It's not coming easy to me, yet.
'description_of_request' is part of a variable set on some of our catalog items. When a request is submitted we want the 'description_of_request' written to 'description' and 'short_description' fields on the RITM and the SCTASK. I wrote the following script in a business rule that works as intended for RITM. However, I cannot figure out how to modify this script to do the same for the SCTASK. How would you modify this script to also set the 'description' and 'short_description' fields on the SCTASK = description_of_request?
(function executeRule(current, previous /*null when async*/ ) {
//Query sc_req_item and match on current.request
//Update short_description and description of req_item with description_of_request from variable set
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.request);
grRITM.query();
while (grRITM.next()) {
current.short_description = grRITM.variables.description_of_request;
current.description = grRITM.variables.description_of_request;
grRITM.update();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 08:43 PM
Sure, I have tried your requirement in my PDI and have got that working now.
Please find the steps below:
1) Create a Before Insert and Update Business Rule on Requested Item table and use the script below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.short_description = current.variables.Variable Name; // Replace "Variable Name" with your variable name
current.description = current.variables.Variable Name; // Replace "Variable Name" with your variable name
})(current, previous);
Now create another Before Insert and Update Business Rule on Catalog Task table and use the script below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.short_description = current.request_item.short_description;
current.description = current.request_item.description;
})(current, previous);
This works for me in my PDI. Let me know if still you are facing an issue.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 06:31 AM
Thanks, Ankur. One of the things I am struggling to understand is, for example, whether to use a Business Rule or a Workflow/Flow Designer for situations like this. Workflow/Flow Designer was one of the last topics we covered in the class. But, I guess I don't understand when to use one verses the other. The instructor mentioned that ServiceNow's goal is to become a code-free environment. So, would you suggest using Workflow/Flow Designer instead of Business Rules scripting?
Thanks,
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 09:07 AM
It depends on your requirement.
If the process is simple then you can use Flow designer.
If the process is complex then you can use workflows
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
01-17-2022 09:30 AM
I was trying to accomplish this with a Business Rule. So, you'd suggest I try the Flow Designer instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 09:37 AM
if you are using flow designer for your catalog item then no need of BR
in the flow itself you can use Update record action and set the fields
1) get the catalog variables
2) then use update action for sc_req_item table and set the field values with the variable values
The record will be the Trigger -> Requested Item Record
If my answer helped you then, please then mark it as correct to close the thread.
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
01-17-2022 10:14 AM
Thanks, Ankur. I will give this a try and let you know how it goes.
Adam