How to put affected CIs in Notification

Richard P
Mega Guru

We have a approval which notifies service managers of potential downtime for a change request as part of the approval process.

we would like to include an iteration of the affected downstream of CIs and business services that are included from the related lists in this change request

in the email notification.

Also as a newcomer I have a real hard time finding the names of the tables and row names I am querying for such things..if anyone can help with that, that would be great too but meanwhile as above, appreciate you looking

Richard

1 ACCEPTED SOLUTION

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Richard



First of all the tables you are looking for are



- 'task_cmdb_ci_service' for the Impacted Services/Cis


- 'task_ci' for the CIs Affected



About the email I suppose you have to work on some email script to be used inside the approval email.


Precisely 'change.itil.approve.role' Email template.



To be clear the OOB approval notification template is shared by different processes (e.g. change service catalog).


For this reason the script you are introducing must be restrictive in order to include the info you need only if you are creating approval for a change.


Other caveat.


I suggest you to don't work directly on the original OOB email template but create a copy and use that one instead.


More information about the email scripts



Scripting for Email Notifications - ServiceNow Wiki



I hope this will help


Robo


View solution in original post

9 REPLIES 9

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Richard



First of all the tables you are looking for are



- 'task_cmdb_ci_service' for the Impacted Services/Cis


- 'task_ci' for the CIs Affected



About the email I suppose you have to work on some email script to be used inside the approval email.


Precisely 'change.itil.approve.role' Email template.



To be clear the OOB approval notification template is shared by different processes (e.g. change service catalog).


For this reason the script you are introducing must be restrictive in order to include the info you need only if you are creating approval for a change.


Other caveat.


I suggest you to don't work directly on the original OOB email template but create a copy and use that one instead.


More information about the email scripts



Scripting for Email Notifications - ServiceNow Wiki



I hope this will help


Robo


Thanks, That is helpful to narrow down the tables, I have set up a separate notification for Downtime approval from the standard 'change.itil.approve.role'



so my script for the impacted services would be something like



var gr=new GlideRecord('task_cmdb_ci_service');


gr.addQuery('???WHAT???', current.sys_id); // to identify the field compare I need


gr.query();


while(gr.next()){


template.print("number:" + gr.getValue('number'));


template.print("short_description", gr.getvalue('short_description'));


}




(I took this from a script for the problem table, there is no change field in the table)


Thank you r0b0_d3vil



Nate23
Mega Guru

Richard,



so one you are looking for Affected CI's related to the CR that you are sending the notification out of. To find the table and fields you need you can do this....



1) on your CR right click Affected CI's related list


2) Personalize/Configure > Table


find_real_file.png


*notice the filter Task = CHGXXXXXXXXX


this is the query you will use to pull the records you need in your email script.



when you get there you should see this:


find_real_file.png



The name field is the name of the table you can reference in a GlideRecord query. Below are the fields in that table. The two key fields are marked ci_item which is the related CI and task which is the related task or in your case CR.



now your email you said is sent out for approval which probably comes from the approval table(sysapproval_approver). you can use the above method to find the table name and fields. There is a Approval for(sysapproval) field which relates to Task. That is your connection to the affected CI's



so in your email script the Current object will be referencing the current Approval record. Approval relates to Task/CR which relates to Affected CI's.



your email script should look something like this



var gr = new GlideRecord('task_ci');


gr.addquery('task', current.sysapproval);


gr.query();



while(gr.next()){


template.print('here is your affected CI: ' + gr.ci_item.name + "/n");


}



then in your email notification body you would enter this to access the script:



${mail_script:script name}




hope this helps,


Nate


Thank you both for your contributions, both were right and leading towards a working solution.



*But, im now seemingly getting a lot of CI's rather than the ones specific to this query



the related list only contains one item, but the query returns the same comprehensive list of many items


regardless of whether the related list contains an item or not, i think the query is wrong slightly although I cannot see why?



current.sysaproval ???