- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 05:01 PM
Hello,
How to create a business rule that grab all the Catalog Tasks that belong to a RITM?
Here is what I have, but it did not work. Please provide suggestions. Thank you
HERE IS THE ENTIRE CODE:
When to run: after insert and update
(function executeRule(current, previous /*null when async*/ ) {
var grTasks = new GlideRecord('sc_task');
grTasks.addQuery('parent', current.sys_id);
grTasks.query();
while (grTasks.next()) {
//do something with the task record
grTasks.short_description = current.short_description;
grTasks.decription = current.decription;
grTasks.assignment_group = "Service Desk";
grTasks.cmdb_ci = "Software";
grTasks.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
08-30-2022 05:53 PM
I will make an assumption of what it it you are looking for. Every catalog task that gets created as part of one particular catalog item needs to be updated with the RITM's short description and description in the corresponding fields, (I hope I'm right?)
Ideally this needs to be done on the Workflow or the Flow designer that is tagged to the catalog item. It's far more easier to maintain that way. Anyway, if for some reason you really have to do it with a BR, then have the BR on Catalog Task table and run it before insert.
Here's your code:
(function executeRule(current, previous /*null when async*/ ) {
current.short_description = current.request_item.short_description;
current.description = current.request_item.description;
})(current, previous);
Also, this can be achieved without any code with a flow designer. Give it a try 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 10:06 AM
I have one last question.
I was trying to update the task short description with the RITM variable, but it did not work.
I must have done it incorrectly. Can you please make correction? Thanks
current.short_description = current.request_item.variables.requested_for;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 06:01 PM
Annie,
I tested this out in my PDI and it works - your code is good.
If the short description isn't updating then there may be several reasons:
- The variable name requested_for could be incorrect
- The field requested_for may not be holding any value
- If the BR was updated to run 'After' the task insert/update, then an additional current.update() is required after the current line. (I'd avoid running After BR entirely)
- At the moment of catalog task creation, there is some other script running at the same time overwriting our update.
Have you tried logging out the value?
gs.info('Mirror mirror on the wall... ' + current.request_item.variables.requested_for);
current.short_description = current.request_item.variables.requested_for;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 08:21 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 06:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 11:42 AM
You have been an excellent teacher. My team and I learned a lot from you.
We are sincerely thank you!