I need to add Affected CIs list to the Change Approval notification

Dawid2
Giga Guru

Hello folks,

I'm in a need to add Affected CIs list to the Change Approval notification that is currently running against sysapproval_approver table.

Using available Fields on the notification doesn't seem to fit any of the requirements and I need to include the list of the Affected CI only on the approval notification against sysapproval_approver table.

Can this be achieved in any way? I have no idea how to script it as I don't know Javascript.

Thanks!

1 ACCEPTED SOLUTION

Changed current.sysapproval too ?



gr.addQuery('u_task', current.sysapproval);


View solution in original post

15 REPLIES 15

Mohamed Faizel
Giga Expert

You can get it by notification email scripts



Step 1:


Go to system policy --> Notitfication Emai Script --> New



Name: get_chage_ci_inemail



Script:


var gr = new GlideRecord('change_request');


gr.addQuery('sys_id', current.sysapproval);


gr.query();


if(gr.next()) {


  template.print(gr.cmdb_ci.getDisplayValue());


}



Step 2:



Go to System Policy --> Notifications -->Change Approval notification



In the message box paste the line whereever you want ${mail_script:get_chage_ci_inemail}



If you are using email template for this notifcation, open the email template and paste the script ${mail_script:get_chage_ci_inemail} in message sections



Thanks,


Faizeal


Anthony_vickery
Tera Expert

Hi Dawid,


You will need to use a notification email script.   This should get you started but you'll probably want to tweak it


var gr = new GlideRecord('task_ci'); // 'Affected CIs' related list table


gr.addQuery('task', current.sys_approval); // only affected ci's for the task that is being approved. "current" refers to the approval record triggering the notification


gr.query(); //execute the query


if (gr.hasNext()) { //check if the query returned any results


      template.print('<br/>Affected CIs:'); //print to the notification


      while (gr.next()) { //loop through each of the returned records


                template.print('<br/>' + gr.ci_item.getDisplayValue()); //print the name of the CI


        }


}


Add it to your approval notification using the following:


${mail_script:getApprovalTaskAffectedCIs}


Thanks Anthony!



It looks good, but on the notification itself it shows only first Affected CI and not all of them (we need all of them):



1.JPG



2.JPG


Change



if (gr.hasNext()) {



To



while(gr.hasNext()) {