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

Close but no dice...



My email notification fires off anytime an order is submitted. No approvals necessary.



Basically they fire anytime the sc_request table gets added to.



Guess i could try:


current.screquest.variables.orderAlternatePOC or something to that degree?



MM


In that case then, you should change your notification to run on the Request Item table, as the variable pool is not available on the Request. Then try your original variations and they may start working.



<mail_script>


template.print(current.variable_pool.orderAlternatePOC);


template.print(current.variables.orderAlternatePOC);


template.print(current.variable.orderAlternatePOC);


</mail_script>


Hey Adam,



That's the ticket. I'm running on the request table, not request item. Also, the ALT POC can be different per orderitem. I'm already iterating through the order to pull back all the order items so I'll just go ahead and pull in ALT POC for each item as well. I'll post my solution shortly.



Thanks much


Hi Matthew,



If you want Request Item variables on Request notifications, then GlideRecord is the only option you've got.



So, you will have to query variables in your existing query that pulls all other request item details.



Thanks,
Mandar


Hey adam,



I used your mail script and my email resulted in EVERY variable (even those not on my form) being show. I changed current.sysapproval to current.sys_id but didn't result in any variables.



What I want to do is just show those variables on the RITM. Here's what I have:



<mail_script>  


printVars();  


 


function printVars() {  


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


      var cv = new GlideRecord('sc_item_option_mtom');  


      cv.addQuery('request_item', current.sys_id);  


      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>');  


      }  


}  


</mail_script>




So, if my catalog item has 3 variables, i'd like to only show those 3 variables.



PS: I'm not using approvals for my orders



Thanks so much for the help