
- 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-18-2022 06:16 AM
Hi Ankur,
Another member helped me get this working with Business Rulees. I am going to stick with that for now. But, I do intend to go back sometime and try to recreate the same process with Flow. Thanks for the help!
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 07:11 AM
No worries.
Please mark my responses helpful if you feel those helped you
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-16-2022 09:29 PM
Let me know if you need futher help with this.
Do answer if you are using a Workflow then or a Flow. Since you are new to ServiceNow, I assume you are using a Flow, which is nowadays the preferred method of ServiceNow. Workflow should not be the first go to.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 06:41 AM
Hi Mark,
I am using a Business Rule. Do you suggest I use Flow instead?
Thanks,
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:42 PM
Hi,
There can be multiple ways to handle this based on how your current catalog is configured whether it is driven by Flow (requires no code for mapping Short and Description), or if it is a Workflow there are activities available through which you can do this.
But if you ae looking from a script learning perspective and want to modify using BR then you can update your existing script itself as below:
(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();
updateCatalogTask(gr);
}
function updateCatalogTask(ritmID){
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',ritmID.sys_id);
gr.query();
while(gr.next()){
gr.short_description = ritmID.short_description;
gr.description = ritmID.description;
gr.update();
}
}
})(current, previous);
Please share your current config details to assist further.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke