Jira Code: NMS-1711
Purpose
We need to remove the email button from the communication tab. But this is not possible so we remove the email button from the message record, which popup while clicking the email button in communication tab.
Description:
Remove the email button from the message record if the approval status is pending ,which is related to the opened PO transaction record. We are using a user event script which will remove the email button before the record load.
Code:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script for removing the email button.
*/
/*******************************************************************************
* * ESW * *
* **************************************************************************
* Date:03/09/19
* Script name:
* Script id:
* Deployment id:
* Applied to: Message Record
*
******************************************************************************/
define(['N/record', 'N/runtime', 'N/search', 'N/email'],
function(record, runtime, search, email) {
/**
* 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 request = scriptContext.request;
var tranId = request.parameters.transaction;
log.debug("tranId", tranId);
//search current transaction
var transactionSearchObj = search.create({
type: "transaction",
filters: [
["internalid", "anyof", tranId]
],
columns: [
search.createColumn({ name: "statusref", label: "Status" }),
search.createColumn({ name: "type", label: "Type" })
]
});
var searchResultCount = transactionSearchObj.runPaged().count;
var status;
var tranType;
log.debug("transactionSearchObj result count", searchResultCount);
transactionSearchObj.run().each(function(result) {
// .run().each has a limit of 4,000 results
status = result.getText({ name: transactionSearchObj.columns[0] });
tranType = result.getText({ name: transactionSearchObj.columns[1] })
return true;
});
//check status and remove button
if (status == 'Pending Supervisor Approval' && tranType == 'Purchase Order') {
scriptContext.form.removeButton({ id: 'submitter' });
}
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
return {
beforeLoad: beforeLoad
};
});