Adding cat item variables to email notification

matthew_magee1
Giga Guru

Hi all,

I think I'm trying to do something pretty simple.

 

I have a few variables on my catalog item form that I need to pull into an email notification. One of the fields being 'alt_poc_phone'

 

I've tried GlideRecord and current.variable_pool.alt_poc_phone and neither seems to work.

 

I've also referenced the following wiki page (Scripting for Email Notifications - ServiceNow Wiki), but something's not clicking (on my part).

 

Any help is greatly appreciated (with examples)

 

MM

1 ACCEPTED SOLUTION

Mandar/Adam-



Follow up to my post. For some reason the mail script is working now. I'm not sure why it wasnt' working earlier. I guess I had a typo or something.



Here's the script that works:



<mail_script>


var item = new GlideRecord("sc_req_item");


item.addQuery("request", current.sys_id);


item.query();


while(item.next()) {


var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();


var misc = item.variable_pool.alt_poc;


template.print(catalogItem + "<br/> Field: " + misc);


}


</mail_script>



Really appreciate the feedback guys, couldn't have done this without you-



On to my next challenge


View solution in original post

41 REPLIES 41

Hi Matthew,



Since you're already querying request items to display item details, so you can just add similar line as below to display the variables used in your item.



//assuming reqItem is your glide record object


reqItem.variable_pool.orderAlternatePOC;



But if you're not sure how many variables there are going to be, you can call above function in your while loop for request items as



printVars(reqItem.getValue("sys_id"));



function printVars(sysId) {


      template.print('<b>Request Details</b>\n');


      var cv = new GlideRecord('sc_item_option_mtom');


      cv.addQuery('request_item', sysId);


      cv.addNotNullQuery('sc_item_option.value');


      cv.orderBy('sc_item_option.order');


      cv.addQuery('sc_item_option.value', '!=', '0');


      cv.query();


      while(cv.next()) {


          template.print('\n' + cv.sc_item_option.item_option_new.question_text + ':\t<b>' + cv.sc_item_option.value + '</b>');


      }


}



Hope that helps.



Thanks,


Mandar



EDIT : Was meant for Matthew, not Adam


Mandar/Adam-



Follow up to my post. For some reason the mail script is working now. I'm not sure why it wasnt' working earlier. I guess I had a typo or something.



Here's the script that works:



<mail_script>


var item = new GlideRecord("sc_req_item");


item.addQuery("request", current.sys_id);


item.query();


while(item.next()) {


var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();


var misc = item.variable_pool.alt_poc;


template.print(catalogItem + "<br/> Field: " + misc);


}


</mail_script>



Really appreciate the feedback guys, couldn't have done this without you-



On to my next challenge


Matt, I'm looking to do something similar.   Where do you place this script?


HI Anthony,



This was done in an email template.


Let me know if I can provide any further info-



matthew


Hi Matthew



I am working on something similar


and I am getting Undefined



Can you please let me know how to resolve this



code


<mail_script>


template.print("PIN: "+current.variables.pin);


template.print("\n email :"+current.variables.email);


</mail_script>



in email it shows as


PIN: undefined


email :undefined