Procurement Notification after PO is created

Jenn18
Kilo Contributor

Hi experts,

 

I’m in need of some notification help. I need to create a notification to send to the Requestor after items have been sourced and a Purchase Order (PO) has been created. I’m trying to include the following items in one notification and I don’t think I’m referencing thing correctly:

  • Request Number
  • Purchase Order(s) linked to the request and their total cost
  • Product model(s) linked to the POs

 

One of the roadblocks I’m running into is that we have multiple vendors, therefore we can have multiple PO’s linked to a request. I can’t figure out how to get a notification to detail all PO’s, all items sourced (not all items requested will be linked to a PO as we have many items in stock, I only want to include items that were purchased), and the complete total cost for that request.

Appreciate any guidance!

Best,

 

Jenn

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You will have to configure email script to get details of multiple PO for one request.

You can then call this email script from your email notification..

 

Check below for email script

 

https://docs.servicenow.com/bundle/london-servicenow-platform/page/script/server-scripting/concept/c_ScriptingForEmailNotifications.html

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

You will have to configure email script to get details of multiple PO for one request.

You can then call this email script from your email notification..

 

Check below for email script

 

https://docs.servicenow.com/bundle/london-servicenow-platform/page/script/server-scripting/concept/c_ScriptingForEmailNotifications.html

 

Regards,

Sachin

Thanks, Sachin. Appreciate the quick reply!

Hi Sachin, 

 

I have another question for you. We were able to get the notification to send and include the data I needed using the mail script I detail below. The issue we're having is that multiple notifications are being sent to the user when there are more than 1 PO's attached to the REQ. The requirement is to have 1 notification sent per REQ, regardless of the amount of PO's linked to the REQ. Any thoughts on how we could accomplish that?

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
gs.log('CORBIN LOG ENTRY');
var costCtr = '';
if (current.u_cost_center.getDisplayValue() == null || current.u_cost_center.getDisplayValue() == ''){
costCtr = 'Not Specified';
}
else{
costCtr = current.u_cost_center;
}

email.subject = 'ServiceNow Hardware ' + current.init_request.number + 'Total Cost to be billed to Cost Center - ' + costCtr;

template.print("<br />");
template.print("<b>Request by: </b> "+ gs.getUser().getUserByID(current.sys_created_by).getDisplayName());
template.print("<br />");
template.print("<b>Requested for: </b> "+ current.requested_for.getDisplayValue());
template.print("<br />");
template.print("<b>Cost Center: </b> " + costCtr);
template.print("<br />");
template.print("<b>Items: </b> ");
template.print("<br />");

var item = new GlideRecord('sc_req_item');
var totalPrice = 0.00;
item.addQuery('request', current.init_request);
item.query();

while(item.next()) {
var u_model = item.cat_item.model.getDisplayValue();
if( u_model != ''){

template.print(item.number+": "+item.quantity+"X "+item.cat_item.getDisplayValue()+" at "+item.price.getDisplayValue() +" each");
template.print("<br />");
template.space(4);
template.print("<b>Short description:</b> "+item.short_description.getDisplayValue());
template.print("<br />");
template.space(4);
template.print("<br /><br />");
}

else {
template.print(item.number+": "+item.cat_item.getDisplayValue());
template.print("<br />");
template.space(4);
template.print("<b>Short description:</b> "+item.short_description.getDisplayValue());
template.print("<br />");
template.space(4);
template.print("<br /><br />");
}
totalPrice = totalPrice + parseFloat(item.price);
}

template.print("<b>Total Cost billed to cost center $</b> " + totalPrice);

})(current, template, email, email_action, event);