- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 08:31 AM - edited ‎05-16-2024 08:32 AM
I have below after business rule to run on Insert, which supposed to insert description on the sc_task by reading all the catalog variables descriptions record but it doesn't. If I change the case to before business rule, it gives error when inserting the record as 'Invalid insert' on page and also a flow associated to this fails as I see it doesn't like grTask.update() call at the end. Any advise on what would be the best way to resolve the issue.?
(function executeRule(current, previous /*null when async*/ ) {
var grTask = new GlideRecord('sc_task');
grTask.get(current.getUniqueValue());
var summaryStr = '';
for (var key in grTask.variables) {
//if key is empty discard the entry
if (grTask.variables[key].getLabel()) {
summaryStr += grTask.variables[key].getLabel() + " ==> " + grTask.variables[key].getDisplayValue() + "\n\n";
}
}
grTask.setValue('description', summaryStr);
grTask.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 09:20 AM
Hi,
Similar question is answered here
Solved: Copy catalog item variables to Task description fi... - ServiceNow Community

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 09:30 AM
@Sri29 Change the business rule to before insert and add the following script in the script field.
(function executeRule(current, previous /*null when async*/ ) {
var summaryStr = '';
for (var key in current.variables) {
//if key is empty discard the entry
if (current.variables[key].getLabel()) {
summaryStr += current.variables[key].getLabel() + " ==> " + current.variables[key].getDisplayValue() + "\n\n";
}
}
current.setValue('description', summaryStr);
}
Since this business rule runs before insert no need to use current.insert() or current.update() in this case.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 09:20 AM
Hi,
Similar question is answered here
Solved: Copy catalog item variables to Task description fi... - ServiceNow Community

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 09:30 AM
@Sri29 Change the business rule to before insert and add the following script in the script field.
(function executeRule(current, previous /*null when async*/ ) {
var summaryStr = '';
for (var key in current.variables) {
//if key is empty discard the entry
if (current.variables[key].getLabel()) {
summaryStr += current.variables[key].getLabel() + " ==> " + current.variables[key].getDisplayValue() + "\n\n";
}
}
current.setValue('description', summaryStr);
}
Since this business rule runs before insert no need to use current.insert() or current.update() in this case.
Hope this helps.