This script is used for creating an email that has file cabinet file content in the email body. when the user clicks a button in the sales order the mail should send to the particular user.
//User Event Script
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
/*************************************************************************************************************************
* CLIENTNAME:PRQ
* PRQ
*
* **********************************************************************************************************************
* Date :1/05/2020
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : Script for creating Button
* Date created : 1/05/2020
*
* REVISION HISTORY
*
* Revision 1.0 ${10/03/2020} Abin: created
*
**************************************************************************************************************************/
define(['N/record'], function (record){
function beforeLoad(context){
try{
if(context.type == 'view'){
context.form.addButton({
id: "custpage_jj_aq_303_test_button",
label: "Button",
functionName : "onButtonClick"
});
}
context.form.clientScriptModulePath = "SuiteScripts/script CS PRQ.js"
}
catch(e){
log.debug('catchError',e)
}
}
return{
beforeLoad: beforeLoad
};
});
//client script button action portion
function onButtonClick(){
var rec=currentRecord.get()
var soid= rec.id
var currenturl = url.resolveScript({
scriptId: "customscript1964",
deploymentId: "customdeploy1",
returnExternalUrl: false
})
window.open (currenturl + "&soid=" + soid)
}
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define(['N/ui/serverWidget'],
function(serverWidget) {
function onRequest(context) {
try{
//sale order id from client script
var soid = context.request.parameters.soid
var objRec=record.load({
type: record.Type.SALES_ORDER,
id: soid,
isDynamic: true
})
//customer name
var customer= objRec.getText({
fieldId:'entity'
})
//customer phone
var phone =objRec.getText({
fieldId:'custbody1'
})
//load File
var fileObj = file.load({
id: 35319
});
//edit HTML
html_value=fileObj.getContents();
log.debug("html_value",html_value)
//replace html
html_value = html_value.replace('<!--name-->',customer);
html_value = html_value.replace('<!--Phone-->',phone);
var senderId = 39956; //empolyee id (sample data)
var recipientId = "name@jobinandjismi.com"; //empolyee email(sender)
email.send({
author: senderId,
recipients: recipientId,
subject: 'Test Sample Email Module',
body: " " +html_value,
});
}
catch(e){
log.debug("error@mail",e)
}
}
return {
onRequest: onRequest
};
});