Jira Code: UMAR 80,24
This script opens an email widget on a custom button click action. We can set necessary values in the email template like sender, recipients, templates, message etc be sending parameters. We can also use the UE applied to message record to fulfil the action. The script also includes the rendering actions to set the attachment as pdf.
//suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/redirect', 'N/record', 'N/email', 'N/render', 'N/config', 'N/search', 'N/file'],
function (redirect, record, email, render, config, search, file) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object}
* context
* @param {ServerRequest}
* context.request - Encapsulation of the incoming request
* @param {ServerResponse}
* context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
try {
// Getting the record id
var recId = context.request.parameters.recId;
var CurrId = context.request.parameters.CurrId;
var custId = context.request.parameters.custId;
var custcont = context.request.parameters.custcont;
var custcontcc = context.request.parameters.custcontcc;
var customerId = context.request.parameters.custemailId;
var customerContCC = context.request.parameters.custemailIdCC;
var sendStatus = context.request.parameters.sendStatus;
var vendorId = context.request.parameters.contact;
var vendorContCC = context.request.parameters.contactCC;
var temp = context.request.parameters.temp;
var usage = context.request.parameters.usage;
var subType = context.request.parameters.subType;
var pdfNm = null;
if (sendStatus == 1) { //sending quotation from quotation record using button 'Quotation'
pdfNm = 'Quotation';
var fileId = createDocumentFile(recId, 109, pdfNm);
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'SendQuotation',
// recepient: customerId,
ccbcclist: customerContCC,
templatetype: 'EMAIL',
entity: customerId,
//subject : subject,
template: temp,
testId: recId,
mediaitem: fileId,
sjType: subType
}
});
} else if (sendStatus == 2) { //send PO from purchase order using the button 'Send PO'
var fileId;
if (CurrId == 1) {
pdfNm = "PurchaseOrder_Parts";
fileId = createDocumentFileForPurchaseOrder(recId, 114, pdfNm);
}
// else {
// pdfNm = "Commission_Invoice";
// fileId = createDocumentFileForInvoice(recId, 123, pdfNm);
// }
log.debug("send po", fileId);
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'SendPO',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
template: temp,
testId: recId,
sjType: CurrId,//subjob type when send PO.
mediaitem: fileId,
}
});
} else if (sendStatus == 3) {//send dispatch details
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: recId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'Dispatch',
templatetype: 'EMAIL',
entity: custcont,
ccbcclist: custcontcc,
template: 29,
testId: recId
}
});
} else if (sendStatus == 4) {//send delivery instructions
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: recId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'deliveryinstructions',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
template: temp,
testId: recId
}
});
} else if (sendStatus == 5) {
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: recId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'RequestDeliveryinstructions',
templatetype: 'EMAIL',
entity: custcont,
ccbcclist: custcontcc,
template: temp,
testId: recId
}
});
} else if (sendStatus == 6) {
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'deliveryinstructions',
templatetype: 'EMAIL',
entity: custId,
// ccbcclist: contactCC,
template: 12,
testId: recId
}
});
} else if (sendStatus == 7) {
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: recId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'requestfrReadiness',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
template: temp,
testId: recId
}
});
} else if (sendStatus == 8) {
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: recId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'RequestDespatchDetails',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
template: temp,
testId: recId
}
});
} else if (sendStatus == 9) { //PO proforma invoice
log.debug('CurrId', CurrId);
var tempalate = 120;
var name = 'Proforma_invoice';
var fileId = createproformaInvDocumentFile_Subjob(CurrId, tempalate, name);
/*var fileId=createDocumentFile(recId,tempalate);
log.debug({
title : 'fileId',
details : fileId
});*/
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'proformaInvoice_PO',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
mediaitem: fileId,
template: 39,// sandbox 34 while porduction 39
testId: recId
}
});
} else if (sendStatus == 10) { //SEND proforma from sales order
var tempalate = 126; // 120 in sandbox while 126 in production
pdfNm = 'Invoice_for_Prepayment';
// var fileId = createDocumentFile(recId, tempalate, pdfNm);
var fileId = createproformaInvDocumentFile_Subjob(recId, tempalate, pdfNm)
log.debug({
title: 'fileId',
details: fileId
});
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'Sendproforma',
// recepient: customerId,
ccbcclist: customerContCC,
templatetype: 'EMAIL',
entity: customerId,
template: 34,
mediaitem: fileId,
testId: recId
}
});
} else if (sendStatus == 11) {//send customer confirmation PO.
var tempalate = 121;
var name = 'Order Confirmation';
//creating send confirmation PO(parts) using SO template.
var fileId = createproformaInvDocumentFile_Subjob(CurrId, tempalate, name);
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'send_customer_confirmation',
templatetype: 'EMAIL',
entity: custcont,
ccbcclist: custcontcc,
template: temp,
testId: recId,
sjType: subType,
mediaitem: fileId
}
});
} else if (sendStatus == 12) {
/* var tempalate=119;
var fileId=(recId,tempalate);
log.debug({
title : 'fileId',
details : fileId
});
*/
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
// record : recId,
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'RequestDeliveryinstructions',
templatetype: 'EMAIL',
entity: custcont,
ccbcclist: custcontcc,
template: 12,
testId: recId
}
});
} else if (sendStatus == 13) { //PO packing list
var tempalate = 115;
var fileId = createpackingListDocumentFile_Subjob(CurrId, tempalate);
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'po_packingList',
templatetype: 'EMAIL',
entity: vendorId,
ccbcclist: vendorContCC,
template: 32,
testId: recId,
mediaitem: fileId
}
});
} else if (sendStatus == 14) { //PROFORMA INVOICE FROM SUBJOB
var tempalate = 128; //120 in sandbox while 128 in production
var name = 'Proforma_invoice';
var fileId = createproformaInvDocumentFile_Subjob(recId, tempalate, name);
log.debug({
title: 'fileId',
details: fileId
});
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: CurrId,
recordtype: 184,
// transaction: recId,
l: 'T',
// iscustom : 't',
usage: 'Sendproforma_subjob',
// recepient: customerId,
ccbcclist: customerContCC,
templatetype: 'EMAIL',
entity: customerId,
template: 39, // 34 in sandbox while 39 in production
mediaitem: fileId,
testId: recId
}
});
} else if (sendStatus == 15) { //PACKING LIST FROM SUBJOB
var tempalate = 127; // 115 in sandbox while 127 in production
var fileId = createpackingListDocumentFile_Subjob(recId, tempalate);
log.debug({
title: 'fileId',
details: fileId
});
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
record: CurrId,
recordtype: 184,
l: 'T',
// iscustom : 't',
usage: 'Sendpacking_subjob',
// recepient: customerId,
ccbcclist: customerContCC,
templatetype: 'EMAIL',
entity: customerId,
template: 39, // 32 in sandbox while 39 in production
mediaitem: fileId,
testId: recId
}
});
} else if (sendStatus == 16) {
log.debug("1", "Im at send status");
log.debug("usage", usage);
var fileId;
if (usage == "send_salesInvoice") {
pdfNm = "Sales_Invoice";
fileId = createDocumentFileForInvoice(recId, 117, pdfNm);
}
else {
pdfNm = "Commission_Invoice";
fileId = createDocumentFileForInvoice(recId, 123, pdfNm);
}
log.debug("fileId", fileId);
// Redirect to a Email message
redirect.toRecord({
type: record.Type.MESSAGE,
id: null,
parameters: {
transaction: recId,
mediaitem: fileId,
l: 'T',
// iscustom : 't',
usage: usage,
templatetype: 'EMAIL',
entity: custcont,
ccbcclist: custcontcc,
template: temp,
testId: recId,
}
});
}
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
return {
onRequest: onRequest
};
/*
* Function to set attachment
*/
function createDocumentFile(recId, tempalate, pdfNm) {
try {
//render The Quote to End user Form
var renderer = render.create();
var subsidiaryDtls = search.lookupFields({
type: search.Type.ESTIMATE,
id: recId,
columns: ['subsidiary']
});
var subsidiaryId = subsidiaryDtls.subsidiary[0].value;
log.debug('subsidiaryId', subsidiaryId);
renderer.setTemplateById(tempalate);
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
renderer.addRecord({
templateName: 'record',
record: record.load({
type: record.Type.ESTIMATE,
id: recId
})
});
renderer.addRecord({
templateName: 'subsidiary',
record: record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId
})
});
//<#if subsidiary.logo?length != 0><img src="${subsidiary.logo@url}" style="width: 200px; height: 80px;float: left; margin: 7px" /> <#else> <#if companyInformation.logoUrl?length != 0> <img src="${companyInformation.logoUrl}" style="width: 80px; height: 80px;float: left; margin: 7px" /> </#if> </#if><p style="font-size: 10pt;">${subsidiary.name}<br />${subsidiary.mainaddress_text}</p>
/* renderer.addRecord({
templateName: 'companyInformation',
record: companyInfo
});
*/
/* renderer = renderer.transaction({
entityId: 3424
});*/
log.debug({
title: "companyInfo",
details: companyInfo
});
var endUserForm = renderer.renderAsPdf();
endUserForm.folder = 7862;
//endUserForm.name = 'Proforma_invoice' + recId + '.pdf';
endUserForm.name = pdfNm + recId + '.pdf';
var fileId = endUserForm.save();
return fileId;
/* return {
size: endUserForm.size,
fileId: endUserForm.save()
}*/
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
function createDocumentFileForInvoice(recId, tempalate, pdfNm) {
try {
log.debug('recId', recId);
var subsidiaryDtls = search.lookupFields({
type: search.Type.INVOICE,
id: recId,
columns: ['subsidiary']
});
var subsidiaryId = subsidiaryDtls.subsidiary[0].value;
var objRecord = record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId,
isDynamic: false
});
log.debug('subsidiaryId', subsidiaryId);
var fileID = objRecord.getValue({
fieldId: 'logo'
});
var fileObj = file.load({
id: fileID
});
log.debug("fileObj", fileObj);
var url = fileObj.url;
url = url.replace(/&/g, '&');
log.debug('fileObj.url', url);
var renderer = render.create();
renderer.setTemplateById(tempalate);
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
var invoice = record.load({
type: record.Type.INVOICE,
id: recId
});
log.debug("invoice", invoice);
renderer.addRecord({
templateName: 'record',
record: invoice
});
renderer.addRecord({
templateName: 'companyInformation',
record: companyInfo
});
renderer.addCustomDataSource({
format: render.DataSource.JSON,
alias: "subsidiary",
data: JSON.stringify({ logo: url })
});
var endUserForm = renderer.renderAsPdf();
log.debug("end user form", endUserForm);
endUserForm.folder = 7862;
endUserForm.name = pdfNm + '_' + recId + '.pdf';
log.debug(endUserForm.name);
var fileId = endUserForm.save();
log.debug(fileId);
return fileId;
}
catch (e) {
log.debug("Exception in create document in invoice", e)
}
}
/*
* Function to set attachment proforma invoice
*/
function createproformaInvDocumentFile_Subjob(recId, tempalate, names) {
try {
var subsidiaryDtls = search.lookupFields({
type: search.Type.SALES_ORDER,
id: recId,
columns: ['subsidiary']
});
var subsidiaryId = subsidiaryDtls.subsidiary[0].value;
//render The Quote to End user Form
var renderer = render.create();
renderer.setTemplateById(tempalate);
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
renderer.addRecord({
templateName: 'record',
record: record.load({
type: record.Type.SALES_ORDER,
id: recId
})
});
renderer.addRecord({
templateName: 'subsidiary',
record: record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId
})
});
renderer.addRecord({
templateName: 'companyInformation',
record: companyInfo
});
/* renderer = renderer.transaction({
entityId: 3424
});*/
log.debug({
title: "companyInfo",
details: companyInfo
});
var endUserForm = renderer.renderAsPdf();
endUserForm.folder = 7862;
// endUserForm.name = 'Proforma_invoice_SO' + recId + '.pdf';
log.debug("end user form2", endUserForm);
endUserForm.name = names + '_' + recId + '.pdf';
var fileId = endUserForm.save();
log.debug(fileId);
return fileId;
/* return {
size: endUserForm.size,
fileId: endUserForm.save()
}*/
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
/*
* Function to set attachment packing list
*/
function createpackingListDocumentFile_Subjob(recId, tempalate) {
try {
/*var transactionFile = render.packingSlip({
entityId: parseInt(recId),
printMode: render.PrintMode.HTML,
inCustLocale: true
});*/
var subsidiaryDtls = search.lookupFields({
type: search.Type.SALES_ORDER,
id: recId,
columns: ['subsidiary']
});
var subsidiaryId = subsidiaryDtls.subsidiary[0].value;
var objRecord = record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId,
isDynamic: false
});
var fileID = objRecord.getValue({
fieldId: 'logo'
});
var fileObj = file.load({
id: fileID
});
var url = fileObj.url;
url = url.replace(/&/g, '&')
log.debug('fileObj.url', url);
//render The Quote to End user Form
var renderer = render.create();
renderer.setTemplateById(tempalate);
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
renderer.addRecord({
templateName: 'record',
record: record.load({
type: record.Type.SALES_ORDER,
id: recId
})
});
renderer.addRecord({
templateName: 'companyInformation',
record: companyInfo
});
renderer.addCustomDataSource({
format: render.DataSource.JSON,
alias: "subsidiary",
data: JSON.stringify({ logo: url })
});
var endUserForm = renderer.renderAsPdf();
endUserForm.folder = 7862;
endUserForm.name = 'Packing_List_SO' + recId + '.pdf';
var fileId = endUserForm.save();
return fileId;
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
function createDocumentFileForPurchaseOrder(recId, tempalate, pdfNm) {
try {
log.debug('recId', recId);
var subsidiaryDtls = search.lookupFields({
type: search.Type.PURCHASE_ORDER,
id: recId,
columns: ['subsidiary']
});
var subsidiaryId = subsidiaryDtls.subsidiary[0].value;
var objRecord = record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId,
isDynamic: false
});
log.debug('subsidiaryId', subsidiaryId);
var fileID = objRecord.getValue({
fieldId: 'logo'
});
var fileObj = file.load({
id: fileID
});
log.debug("fileObj", fileObj);
var url = fileObj.url;
url = url.replace(/&/g, '&');
log.debug('fileObj.url', url);
var renderer = render.create();
renderer.setTemplateById(tempalate);
var companyInfo = config.load({
type: config.Type.COMPANY_INFORMATION
});
var purchaseOrder = record.load({
type: record.Type.PURCHASE_ORDER,
id: recId
});
log.debug("purchase order", purchaseOrder);
renderer.addRecord({
templateName: 'record',
record: purchaseOrder
});
renderer.addRecord({
templateName: 'companyInformation',
record: companyInfo
});
renderer.addCustomDataSource({
format: render.DataSource.JSON,
alias: "subsidiary",
data: JSON.stringify({ logo: url })
});
var endUserForm = renderer.renderAsPdf();
log.debug("end user form", endUserForm);
endUserForm.folder = 7862;
endUserForm.name = pdfNm + '_' + recId + '.pdf';
log.debug(endUserForm.name);
var fileId = endUserForm.save();
log.debug(fileId);
return fileId;
}
catch (e) {
log.debug("Exception in create document in invoice", e)
}
}
});
User event
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script for setting the recipient and message in email message
* After sending the mail update the RFQ Date and change the sub job status to Awaiting Offer
*/
/*******************************************************************************
* * UMAR WSR * *
* **************************************************************************
* Date:14/2/18 Script name: NetU UE Attach Requisition Script id:
* customscript_netu_ue_attach_requisition Deployment id:
* customdeploy_netu_ue_attach_requisition Applied to: Message Record
*
* revised : au 04/06/2018
*
******************************************************************************/
define(
['N/email', 'N/record', 'N/search', 'N/url', 'N/https', 'N/format'],
function (email, record, search, url, https, format) {
/*
* Function to change the sub job status in all related records
*/
function changeStatus(subjobId, st) {
try {
// Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_change_status',
deploymentId: 'customdeploy_netu_sl_change_status',
returnExternalUrl: true,
}) + '&subJobId=' + subjobId + '&statusNo=' + st;
log.debug({
title: 'SL',
details: output
});
https.get({
url: output
});
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object}
* scriptContext
* @param {Record}
* scriptContext.newRecord - New record
* @param {string}
* scriptContext.type - Trigger type
* @param {Form}
* scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
try {
var entryString = scriptContext.newRecord.getValue({
fieldId: 'entryformquerystring'
});
var indexOfiscustom = entryString.indexOf('iscustom');
var request = scriptContext.request;
var isCustom = request.parameters.iscustom;
var usage = request.parameters.usage;
var mediaitem = request.parameters.mediaitem;
var subJobType = request.parameters.sjType;
var transaction = request.parameters.testId;
log.debug({
title: 'mediaitem11',
details: mediaitem + ',' + usage
});
log.debug("usage", usage);
if (indexOfiscustom > 0) {
// Check whether message created is custom
if (isCustom == 't' && usage == 'SendRequisition') {
var emailId = request.parameters.recepient;
var ccbcclist = request.parameters.ccbcclist;
var msg = request.parameters.msg;
//var templateId = request.parameters.templateId;
var mediaitem = request.parameters.mediaitem;
var subJobType = request.parameters.sjType;
var objRecord = scriptContext.newRecord;
// Set the recipient mail id
objRecord.setText({
fieldId: 'recipient',
text: emailId,
ignoreFieldChange: true
});
// Set the recipient mail id cc
if ((ccbcclist != '')) {
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'cc',
value: true,
line: 0,
ignoreFieldChange: true
});
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'email',
value: ccbcclist,
line: 0,
ignoreFieldChange: true
});
}
// Set the recipient mail id
objRecord.setText({
fieldId: 'recipienttype',
text: 'Contact',
ignoreFieldChange: true
});
// Set the Message body
/*
* objRecord.setText({ fieldId: 'message', text:
* msg, ignoreFieldChange: true });
*/
// Set the template
/* objRecord.setText({
fieldId : 'template',
text : templateId,
ignoreFieldChange : false
});*/
if (subJobType == 1) {
// Attaching the customer file in the email
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: mediaitem,
line: 0,
ignoreFieldChange: true
});
}
}
}
if ((usage == 'SendQuotation') || (usage == 'SendPO' && subJobType == 2) ||
(usage == 'proformaInvoice_PO') || (usage == 'po_packingList') ||
(usage == 'send_customer_confirmation') || (usage == 'SendproformaSO') || (usage == 'sendInvoice') || (usage == 'Sendproforma') ||
(usage == 'send_salesInvoice') ||
(usage == 'send_commiInvoice')
) {
//setting cc list
var ccbcclist = request.parameters.ccbcclist;
var objRecord = scriptContext.newRecord;
objRecord.setValue({
fieldId: 'includetransaction',
value: false,
ignoreFieldChange: false
});
// Set the recipient mail id cc
if ((ccbcclist != '')) {
try {
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'cc',
value: true,
line: 0,
ignoreFieldChange: true
});
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'email',
value: ccbcclist,
line: 0,
ignoreFieldChange: true
});
}
}
//adding packing and prforma(if it is already created) when sending po from PO.
if (usage == 'SendPO' /*&& subJobType == 2*/) {
var objRecord = scriptContext.newRecord;
log.debug('transaction', transaction);
//getting the sub job type
var purchdtls = search.lookupFields({
type: search.Type.PURCHASE_ORDER,
id: transaction,
columns: ['custbody_netu_proforma_invoice', 'custbody_netu_packing_list']
});
var i = 0;
if (purchdtls.custbody_netu_proforma_invoice != null && purchdtls.custbody_netu_proforma_invoice != "" && purchdtls.custbody_netu_proforma_invoice != undefined) {
var proforma_invoice = purchdtls.custbody_netu_proforma_invoice;
log.debug('proforma_invoice', proforma_invoice);
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: proforma_invoice,
line: i,
ignoreFieldChange: true
});
i++;
}
if (purchdtls.custbody_netu_packing_list != null && purchdtls.custbody_netu_packing_list != "" && purchdtls.custbody_netu_packing_list != undefined) {
var packing_list = purchdtls.custbody_netu_packing_list;
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: packing_list,
line: i,
ignoreFieldChange: true
});
i++;
}
if (subJobType == 1) {
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: mediaitem,
line: i,
ignoreFieldChange: true
});
}
}
//adding packing and proforma(if it is already created) when sending delivery instructions from subjob.
if (usage == 'deliveryinstructions') {
var objRecord = scriptContext.newRecord;
log.debug('transaction', transaction);
//getting the sub job type
var subjobDtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: transaction,
columns: ['custrecord_netu_proforma_invoice', 'custrecord_netu_packing_list']
});
var i = 0;
if (subjobDtls.custrecord_netu_proforma_invoice != null && subjobDtls.custrecord_netu_proforma_invoice != "" && subjobDtls.custrecord_netu_proforma_invoice != undefined) {
var proforma_invoice = subjobDtls.custrecord_netu_proforma_invoice;
log.debug('proforma_invoice', proforma_invoice);
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: proforma_invoice,
line: i,
ignoreFieldChange: true
});
i++;
}
if (subjobDtls.custbody_netu_packing_list != null && subjobDtls.custbody_netu_packing_list != "" && subjobDtls.custbody_netu_packing_list != undefined) {
var packing_list = subjobDtls.custrecord_netu_packing_list;
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: packing_list,
line: i,
ignoreFieldChange: true
});
}
}
if ((usage == 'Dispatch') ||
(usage == 'deliveryinstructions') ||
(usage == 'requestfrReadiness') ||
(usage == 'RequestDeliveryinstructions') ||
(usage == 'RequestDespatchDetails') ||
(usage == 'Sendproforma_subjob') ||
(usage == 'Sendpacking_subjob') ||
(usage == 'MainJob_acknowledgment')) {
//setting cc list
var ccbcclist = request.parameters.ccbcclist;
var objRecord = scriptContext.newRecord;
// Set the recipient mail id cc
if ((ccbcclist != '')) {
log.debug({
title: 'ccbcclist2',
details: ccbcclist
});
try {
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'cc',
value: true,
line: 0,
ignoreFieldChange: true
});
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
objRecord.setSublistValue({
sublistId: 'otherrecipientslist',
fieldId: 'email',
value: ccbcclist,
line: 0,
ignoreFieldChange: true
});
}
}
if ((usage == 'Sendproforma') ||
(usage == 'SendQuotation' && subJobType == 1) ||
(usage == 'Sendproforma_subjob') ||
(usage == 'Sendpacking_subjob') ||
(usage == 'proformaInvoice_PO') ||
(usage == 'po_packingList') ||
(usage == 'send_customer_confirmation' && subJobType == 1) ||
(usage == 'send_salesInvoice') ||
(usage == 'send_commiInvoice')) {
log.debug({
title: 'SendproformaInmediaItem'
});
//setting cc list
var ccbcclist = request.parameters.ccbcclist;
var objRecord = scriptContext.newRecord;
//var mediaitem = request.parameters.mediaitem;
log.debug({
title: 'mediaitem22',
details: mediaitem
});
objRecord.setSublistValue({
sublistId: 'mediaitem',
fieldId: 'mediaitem',
value: mediaitem,
line: 0,
ignoreFieldChange: true
});
}
} catch (e) {
log.debug({
title: 'EmailWidget',
details: e.message
});
}
}
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object}
* scriptContext
* @param {Record}
* scriptContext.newRecord - New record
* @param {Record}
* scriptContext.oldRecord - Old record
* @param {string}
* scriptContext.type - Trigger type
* @Since 2015.2
*/
function afterSubmit(scriptContext) {
try {
var proforma_invoice = null;
var packing_list = null;
var entryString = scriptContext.newRecord.getValue({
fieldId: 'entryformquerystring'
});
//var res = entryString.split("transaction=");
var res = entryString.split("testId=");
var recId = res[1].split("&");
// getting current date
var today = new Date();
var athens = format.format({
value: today,
type: format.Type.DATETIME,
timezone: format.Timezone.EUROPE_ISTANBUL
})
var todayDate = athens.split(" ");
if (entryString.indexOf('MainJob_acknowledgment') > 0) {
record.submitFields({
type: 'customrecord_netu_main_job',
id: recId[0],
values: {
'custrecord_netu_mj_emailstatus': true
}
});
}
var indexOfSendRequisition = entryString.indexOf('SendRequisition');
if (indexOfSendRequisition > 0) {
var idOfEmail = scriptContext.newRecord.id;
log.debug('idOfEmail', idOfEmail);
// Change the Sub-job status field value to Awaiting
// Offer
record.submitFields({
type: 'customrecord_netu_purchase_requisition',
id: recId[0],
values: {
'custrecord_netu_req_sub_job_status': '2',
'custrecord_netu_send_req_mail_id': idOfEmail,
'custrecord_netu_req_rfq_date': todayDate[0]
}
});
var jobIds = search.lookupFields({
type: 'customrecord_netu_purchase_requisition',
id: recId[0],
columns: ['custrecord_netu_sub_job_number',
'custrecord_netu_pur_req_main_job'
]
});
var subJobid = jobIds.custrecord_netu_sub_job_number[0].value;
var mainJobid = jobIds.custrecord_netu_pur_req_main_job[0].value;
// Change the Sub-job status to Awaiting Offer in the
// Sub-job record
record.submitFields({
type: 'customrecord_netu_sub_job',
id: subJobid,
values: {
custrecord_netu_subjob_status: '2'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
// Change the Sub-job status to New Job in the Main job
// record
record.submitFields({
type: 'customrecord_netu_main_job',
id: mainJobid,
values: {
custrecord_netu_job_status: '1'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
var st = '2';
changeStatus(subJobid, st);
}
//setting status after sending quotation.
var indexOfSendQuotation = entryString.indexOf('SendQuotation');
if (indexOfSendQuotation > 0) {
record.submitFields({
type: record.Type.ESTIMATE,
id: recId[0],
values: {
'custbody_netu_offer_sent_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting status after sending PO.
var indexOfSendRequisition = entryString.indexOf('SendPO');
if (indexOfSendRequisition > 0) {
record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: recId[0],
values: {
'custbody_netu_subjob_status': '9',
'custbody_netu_order_sent_date': athens
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending customer confirmation.
var indexOfSendcustConfirm = entryString.indexOf('send_customer_confirmation');
if (indexOfSendcustConfirm > 0) {
record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: recId[0],
values: {
'custbodynetu_send_cust_confirmatn': '1'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending proforma.
var indexOfSendProforma = entryString.indexOf('proformaInvoice_PO');
if (indexOfSendProforma > 0) {
var res = entryString.split("mediaitem=");
proforma_invoice = res[1].split("&");
record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: recId[0],
values: {
'custbody_netu_proforma_invoice': proforma_invoice[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
log.debug("i finished after submit")
}
//setting request for readiness in date in sub job
var indexOfReadinessRqst = entryString.indexOf('requestfrReadiness');
if (indexOfReadinessRqst > 0) {
var st = 12;
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recId[0],
values: {
'custrecord_netu_po_readiness_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
changeStatus(recId[0], st);
}
//setting request for delivery instructions date in sub job
var indexOfRqstDelivery = entryString.indexOf('RequestDeliveryinstructions');
if (indexOfRqstDelivery > 0) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recId[0],
values: {
'custrecord_netu_so_req_delivery_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting send delivery instructions date in sub job
var indexOfRqstDeliveryInstructn = entryString.indexOf('deliveryinstructions');
if (indexOfRqstDeliveryInstructn > 0) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recId[0],
values: {
'custrecordnetu_po_delivery_instr_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting request for dispatch details date in sub job
var indexOfRqstForDispatch = entryString.indexOf('RequestDespatchDetails');
if (indexOfRqstForDispatch > 0) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recId[0],
values: {
'custrecord_netu_po_requ_desp_det_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting request for dispatch details date in sub job
var indexOfDispatch = entryString.indexOf('Dispatch');
if (indexOfDispatch > 0) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recId[0],
values: {
'custrecord_netu_so_desp_det_date': todayDate[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending proforma.
var indexOfSendPackingPO = entryString.indexOf('po_packingList');
if (indexOfSendPackingPO > 0) {
var res = entryString.split("mediaitem=");
packing_list = res[1].split("&");
record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: recId[0],
values: {
'custbody_netu_packing_list': packing_list[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending sales invoice.
var indexOfSendProforma = entryString.indexOf('send_commiInvoice');
if (indexOfSendProforma > 0) {
record.submitFields({
type: record.Type.INVOICE,
id: recId[0],
values: {
'custbody_sending_ci': '1'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending commission invoice.
var indexOfSendProforma = entryString.indexOf('send_salesInvoice');
if (indexOfSendProforma > 0) {
record.submitFields({
type: record.Type.INVOICE,
id: recId[0],
values: {
'custbody_sending_si': '1'
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending proforma invoice.(subjob)
var indexOfSendProformaSubjob = entryString.indexOf('Sendproforma_subjob');
if (indexOfSendProformaSubjob > 0) {
var recordDtls = entryString.split("record=");
recordId = recordDtls[1].split("&");
var res = entryString.split("mediaitem=");
proforma_invoice = res[1].split("&");
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recordId[0],
values: {
'custrecord_netu_proforma_invoice': proforma_invoice[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
//setting a hidden fields value after sending packing list.(subjob)
var indexOfSendPackingSubjob = entryString.indexOf('Sendpacking_subjob');
if (indexOfSendPackingSubjob > 0) {
var recordDtls = entryString.split("record=");
recordId = recordDtls[1].split("&");
var res = entryString.split("mediaitem=");
packing_list = res[1].split("&");
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recordId[0],
values: {
'custrecord_netu_packing_list': packing_list[0]
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
} catch (e) {
log.debug({
title: 'After Submit',
details: e.message
});
}
}
return {
beforeLoad: beforeLoad,
afterSubmit: afterSubmit,
changeStatus: changeStatus
};
});