How to populate Request For name in Email notification

shaik_irfan
Tera Guru

Hello Everyone,

i want to populate Requested By name under Email template, Requested For (u_req_for) is from RITM table which should be populated on Template i tried Select Variables which is present in the Template but i unable to find the Requested For name since the email template is written on Approval table.

Can anyone please help me out how to populate the RITM table field on Approval table ?

1 ACCEPTED SOLUTION

Rajesh feedbacks were helpful but you will still need to query the req_item table;



Please try this just for the fun somewhere on your code



<mail_script>


var ritm = new GlideRecord('sc_req_item');


if(ritm.get(current.sysapproval)){


var req_for = ritm.u_req_for.name;


template.print("Requested for :"+ritm.request.requested_for.name);


template.print("Requested by :"+ritm.u_req_for.name);


}


</mail_script>


View solution in original post

27 REPLIES 27

Rajesh,



Above image which i sent earlier was from Notification preview button only where Req for is empty but Req for under RITM table is not empty,



Let me tell you my notification is written on Approval table i think thats the reason i unable to see Requested for on Select Field icon which i present in template, As my notification was written on Approval how to call RITM field under notification template


Rajesh feedbacks were helpful but you will still need to query the req_item table;



Please try this just for the fun somewhere on your code



<mail_script>


var ritm = new GlideRecord('sc_req_item');


if(ritm.get(current.sysapproval)){


var req_for = ritm.u_req_for.name;


template.print("Requested for :"+ritm.request.requested_for.name);


template.print("Requested by :"+ritm.u_req_for.name);


}


</mail_script>


Let me try Younes,



Just wanted to confirm 1 thing when i click on Revert to plain text editor i can found the script in text form but later i unable to revert back to HTML view since i unable to find Revert back to HTML link in Related links.



As this is my Dev instance i am little worried to click on Revert to plain text


How to switch back to HTML



On my instance I have this button to switch back to HTML



find_real_file.png


If not (I'll be surprise) it is still possible to switch back from a list view;


- Add column sys version


- Switch to v2 (HTML editor)



find_real_file.png




Edit the plaintext on a template



Unfortuantely if servicenow doesn't display the message field you will have to add it yourself by doing a configure >   form layout.




find_real_file.png



You can then put your code there


Thank you so much Younes,



I got it when i try in my Dev instance



But there is an issue as i change it to plain text editor and later when i click on Switch HTML Editor my template is completely changed, as there is a Standard format which was been designed.



Can i write that code some other place ex: under notification scripting and call that script in my template:



Just like below:


find_real_file.png



at the place of sysapproval.requested_for can i give email script name to display the request for name ?



if yes please guide me where to write to script and how to call it in my template. It would be very helpful for me