add comment to parent when RITM gets created

Carol13
Kilo Expert

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();

}

1 ACCEPTED SOLUTION

Kartik Sethi
Tera Guru
Tera Guru

Hi @Carol 

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Carol 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Carol 

You can also check the above optimized script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader