Sales Order email notification.

Jira Code: CN-19
Once a Sales order is created an email notification is to be sent to the approvers.

Workflow Action Script:

/**
 * @NApiVersion 2.x
 * @NScriptType workflowactionscript
 */
/*******************************************************************************
* CLIENTNAME:C2 NATIVE
* CN-19
*  WORKFLOW TO SEND EMAIL TO APPROVERS ON SALES ORDER CREATION
* **************************************************************************
* Date : 02-11-2018
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to  send an email to the approvers Antonio and Cumai on SO creation
* Date created : 02-11-2018
*
* REVISION HISTORY
*
* Revision 1.0 ${date} nd : created
* 
*
******************************************************************************/
define(['N/search','N/email','N/runtime','N/record'],

function(search,email,runtime,record) {
   
    /**
     * Definition of the Suitelet script trigger point.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.newRecord - New record
     * @param {Record} scriptContext.oldRecord - Old record
     * @Since 2016.1
     */
    function onAction(scriptContext) {
    	try{
    		var salesOrderId = scriptContext.newRecord.id;
    		//to get the sales order number
    		var SOnum = search.lookupFields({
    		    type: search.Type.SALES_ORDER,
    		    id: salesOrderId,
    		    columns: ['tranid']
    		});
    		//to get the internalid of current user
    		var userObj = runtime.getCurrentUser();
            var employeeSearchObj = search.create({
            	   type: "employee",
            	   filters:
            	   [
            	      ["entityid","is","Antonio Emanuele Mara"], 
            	      "OR", 
            	      ["entityid","is","Cumai Aboul Housn"]
            	   ],
            	   columns:
            	   [      	   
            	      search.createColumn({name: "internalid", label: "Internal ID"})
            	   ]
            	});
        	var searchResult = employeeSearchObj.run().getRange({
           		start:0,
           		end:100
           	});
    		var m = searchResult.length;
    	 	for(var i=0;i<m;i++){
          		var EmpId = searchResult[i].getValue({
          		    name: 'internalid'
          		  });
          		email.send({
        		    author: userObj.id,
        		    recipients: EmpId,
        		    subject: 'Sales Order Created ',
        		    body: 'You have a Sales Order '+SOnum.tranid+' for approval',
        		    
        		      });
          	}
    	}catch(er){
    		log.error('error',er)
    	}
    	

    }

    return {
        onAction : onAction
    };
    
});

Leave a comment

Your email address will not be published. Required fields are marked *