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



current.sysaproval is correct.



I suppose for some reason current.sysapproval is not available and the system is executing a * query.


Use gs.log(current.sysapproval) to check if the right task id is visible.



Robo






Thanks once again Robo



urrent.sysapproval does tally up with the sysid of the task


except the task seems to have a ^ on the end when I copy the task query in the related list i get



task=3a0d09714f061200c369e3518110c783^



which is the only real difference from the current.sys approval



only half knowing what Im doing I tried ammending the query to



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



but that also produce the same results, seems no matter what I put in there I get the exact list of CI's back suggesting the query is not narrowing the results down at all.   this is my complete script based on yours and Nate's advice.



var gr = new GlideRecord('task_ci');


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


gr.query();


gs.log(current.sysapproval);




while(gr.next()){


  template.print(gr.ci_item.name + "\n");


}


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Richard



Did you check the log after creating the email ?



You can find the log under System Logs > System Log > Script Log Statements.



Maybe you can add to your code something like this in order to find the result easily into the log.



gs.log('Email Approval >> ' + current.sysapproval);



Another option you have is also to execute the code



var id = 'YOUR_TASK_SYS_ID_HERE';


var gr = new GlideRecord('task_ci');


gr.addquery('task', id);


gr.query();


while(gr.next()){


    gs.print(gr.ci_item.name);


}



in a back ground script window and check if the result is showing exactly the list of CIs you expect.


Awe Man!!!



You know what it was



addQuery (i had addquery)



Thank you very much for your help.


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Richard



It is possible to execute server side code directly without using business rules or anything else.


You need to activate the high security and than search on the left side navigation bar a module named 'Background script'.


If you use that link you will be redirected to the background script window.


You can cut and paste the code



var id = '6c7ab4ce4fc61200c369e3518110c730';


var gr = new GlideRecord('task_ci');


gr.addquery('task', id);


gr.query();


while(gr.next()){


  gs.print(gr.ci_item.name);


}



and Run the script directly.



IMPORTANT Be careful with this editor because, of course, you can execute directly the code but you can execute any type of code.


For instance not just QUERY but also UPDATES INSERTS or DELETE. So you can have disruptive effect on the instance.


The code above should be fine because it is a simple query.