I am trying to update the case comments when an incident is opened for the case but struggling to get it working!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2019 07:27 AM
I have a requirement to notify a customer via the 'additional comments' in the case record, when there is an incident created for the original case record in CMS using the Service Management Integration plugin..
I have been trying to use a
Before Insert business rule on the Incident table using this script below (+many more attempts!!)
(function executeRule(current, previous /*null when async*/) {
var inc_num = current.number;
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();
while(caseGr.next()) {
caseGr.comments= "The following incident has been opened for this case " + current.number + " | " + current.short_description ;
caseGr.update();
}
})(current, previous);
Any help would be appreciated
Regards,
Seamus
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2019 07:32 AM
Hi,
comments field is a journal field.
Can you try to use this and check
(function executeRule(current, previous /*null when async*/) {
var inc_num = current.number;
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addQuery("incident",current.sys_id);
caseGr.addActiveQuery();
caseGr.query();
var fieldName = 'comments';
while(caseGr.next()) {
var value = "The following incident has been opened for this case " + current.number + " | " + current.short_description;
caseGr[fieldName].setJournalEntry(value);
caseGr.update();
}
})(current, previous);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
10-21-2019 07:38 AM
Your script should workw with an after BR.
(function executeRule(current, previous /*null when async*/) {
var inc_num = current.number;
var caseGr = new GlideRecord("sn_customerservice_case");
caseGr.addQuery("incident",current.sys_id); //I dont see incident as an OOB field, please check this dictionary name something like u_incident if it is custom created
caseGr.addActiveQuery();
caseGr.query();
while(caseGr.next()) {
caseGr.comments= "The following incident has been opened for this case " + current.number + " | " + current.short_description ;
caseGr.update();
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2019 08:20 AM
Hi,
I tried Ankur's script and it is updating the record however it is also updating all of the case records in the system. So it seems there is an issue with the addQuery statement as per Prateek's comment
caseGr.addQuery("incident",current.sys_id); //I don't see incident as an OOB field, please check this dictionary name something like u_incident if it is custom created.
I struggle to work out how to query the specific case that is related to the incident, does anybody have an example of an addQuery for the case/incident relationship?
Thanks in advance,
Seamus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2019 09:14 AM
Try
caseGr.addQuery("u_incident",current.sys_id);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks