- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 09:34 AM
Hi Community,
How to fetch the incident number in the problem notification?
I have tried below email script but i didnt get expected results.
Code:
template.print("<p><Related incidents:<br />");
var gr = newGlideRecord("incident");
gr.addQuery("problem_id", current.sys_id);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.number.getDisplayValue() "<br />");
}
Appriciated for the quick reply.
Thanks in advance,
Shrinivasprasad
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 01:29 AM
Updated
template.print("<p>Related incidents: <br></p>");
var gr = new GlideRecord("incident");
gr.addQuery("problem_id", current.sys_id);
gr.query();
while(gr.next()) {
template.print(gr.getValue('number') + ": " + gr.getDisplayValue('number') + "<br>");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 09:43 AM
Hi
So when problem state changes the notification should trigger
It should send email to the caller of the incident which is linked to this problem
Please follow this steps
1) Create event on incident table
2) Create notification on incident table and link the above incident
3) Write After Update BR on Problem table
4) Condition: State changes to Whatever you want
5) Script below
var gr = new GlideRecord('incident');
gr.addQuery('problem_id',current.sys_id);
gr.query();
while(gr.next()){
gs.eventQueue('event_name', gr, gr.caller_id, '');
}
6) Create Email Script to show the content; Actually there is no need to use email script
Directly you can access the fields of incident record in email body
7) Link the email script to the notification body
Sample Email Script
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Number' + current.number);
template.print('State' + current.state.getDisplayValue());
})(current, template, email, email_action, event);
Refer to this link by Ankur: https://community.servicenow.com/community?id=community_question&sys_id=09c5ca96dbda5890b1b102d5ca961958
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 12:59 AM
Hi Sandeep,
i tried this but it is fetching the problem ticket number instead of incident number.
Any suggestions please.
Thanks,
Shrinivasprasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 09:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 09:56 AM
Hello Shrinivas,
Why do you want to use script when you can directly get incident number through 'parent' field like below.? I'm seeing one OOB notification wherein they are fetching incident number using parent.? Please go through sample notification and screenshot. Mark my answer as correct or hit like based on impact.
Notification : https://yourinstance/sysevent_email_action.do?sys_id=f5c86dfc2f1501102f4db8e72799b6d6&sysparm_record_target=sysevent_email_action&sysparm_record_row=1&sysparm_record_rows=471&sysparm_record_list=active%3Dtrue%5EORDERBYDESCsys_created_on
Screenshot
Regards,
Musab