Wednesday, February 6, 2019

Send an email when Purchase Order is in Pending Approval status

When a new purchase order is created, e-mail is sent out only after the transaction record is approved. This is expected behavior as generally, sending out unapproved purchase orders is not desired.

An alternate solution for this is to create a custom User Event script which sends the e-mail for such scenario:

function userEventAfterSubmit(type) {

    // get new record data
    var rec = nlapiGetNewRecord();

    // continue only when this is a new record (type = create)
    // and when the order needs approval (supervisorapproval = F)
    if ((type == 'create') && (rec.getFieldValue('supervisorapproval') == 'F')) {

        // get context information (used to set e-mail sender)
        var context = nlapiGetContext();

        // create HTML with Transaction details
        var mailRec = nlapiPrintRecord('TRANSACTION', rec.getId(), 'HTML', null);

        // send Transaction details to e-mail set on Communication tab
        nlapiSendEmail(context.getUser(), rec.getFieldValue('email'),
          'New Purchase Order [Pending Approval]', mailRec.getValue());
    }
}

Note: E-mail subject and body can be customized so that the recipient knows this Purchase Order is not yet approved.

No comments:

Post a Comment