How to fetch the incident number in the problem notification.

shrinivasprasad
Tera Expert

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

1 ACCEPTED SOLUTION

Updated @Smudge original script:

 

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>");
}

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

Hi @shrinivasprasad ,

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

Hi Sandeep,

 i tried this but it is fetching the problem ticket number instead of incident number.

Any suggestions please.

Thanks,

Shrinivasprasad

Shakeel Shaik
Giga Sage
Giga Sage

Hi @shrinivasprasad 

 

Use <br> 

 

instead of 

find_real_file.png

 

Please check and let me know

Thanks:)

Thanks,
Shakeel Shaik 🙂

Musab Rasheed
Tera Sage
Tera Sage

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

Please hit like and mark my response as correct if that helps
Regards,
Musab