- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 02:39 AM
Hi ,
When a ritm is created, it usually is accompanied with a case. the parent field gets filled with that case and this business rule should run and a comment should get created to the case.
I am trying to get my before insert/update business rule to run, but nothing is appearing on the case record.
conditions: item category is consumables, parent is not empty
at the moment this is the code:
var caseRecord = new GlideRecord('sn_customerservice_case');
caseRecord.addQuery('sys_id', current.parent);
caseRecord.addActiveQuery();
caseRecord.query();
if(caseRecord.next()) {
caseRecord.comment = "Note from Related RITM" + current.number + " Item Category is Consumables";
caseRecord.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 03:10 AM
Hi
There is a typo:
caseRecord.comments
As per your requirement, it doesn't seem that you want to sync comments to Case from RITM, so you can go for an after Business Rule which runs on Insert/Update.
Rest all looks good.
There could only be a chance that the Case might be getting created a little than RITM and Case record might not be present at that time.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 03:36 AM
Hi,
your BR should be after update and script can be optimized and no need to query
var ref = current.parent.getRefRecord();
ref.comments = "Note from Related RITM" + current.number + " Item Category is Consumables";
ref.update();
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-20-2022 04:22 AM
You can also check the above optimized script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader