Restrict the payment method NetSuite and Credit Memo in the customer deposit record for all the roles other than Admin and Accounting Manager
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/********************************************
* * Restrict Customer Deposit Payment Method
*
* ******************************************************
*
* Author: Jobin and Jismi IT Services
*
* Date Created :01 -March-2023
*
* Created By: Aswathy, Jobin and Jismi IT Services
*
* Description : Restrict Customer Deposit Payment Method
*
* REVISION HISTORY
*
**********************************************************/
define(['N/currentRecord', 'N/record','N/runtime'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{runtime}runtime
*/
function(currentRecord, record,runtime) {
/**
* Defines the Roles
* @type {{ACCOUNTING_MANAGER: number, ADMINS: string, ADMIN: number, ACCOUNTING_MANAGERS: string}}
*/
const ROLES_OBJECT = {
ADMIN: 3,
ADMINS: '3',
ACCOUNTING_MANAGERS :'1099',
ACCOUNTING_MANAGER :1099,
}
/**
* Defines the Payment Methods
* @type {{PRE_NETSUITE: string, CREDIT_MEMO: string}}
*/
const PAYMENT_METHODS = {
PRE_NETSUITE: '23',
CREDIT_MEMO:'24'
}
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
}
/**
* Validation function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @returns {boolean} Return true if field is valid
*
* @since 2015.2
*/
function validateField(scriptContext) {
try
{
console.log("validate field...");
var currentRole = runtime.getCurrentUser().role
var currentRecord = scriptContext.currentRecord;
/**
* When the current user role is other than Admin or Accounting Manager show an alert when try to choose the payment methods
* either Pre-NetSuite or Credit memo
*/
if(currentRole !== ROLES_OBJECT.ADMIN && currentRole !== ROLES_OBJECT.ADMINS && currentRole !== ROLES_OBJECT.ACCOUNTING_MANAGER && currentRole !== ROLES_OBJECT.ACCOUNTING_MANAGERS)
{
if (scriptContext.fieldId === 'paymentmethod') {
console.log("the current user is not admin / accounting manager")
var paymentMethod = currentRecord.getValue({
fieldId:'paymentmethod'
})
console.log("paymentMethod",paymentMethod);
var flag=true
if(paymentMethod == PAYMENT_METHODS.PRE_NETSUITE || paymentMethod ==PAYMENT_METHODS.CREDIT_MEMO)
{
alert("You do not have the permission to choose ‘Pre-Netsuite’ and ‘Credit Memo’ payment methods.")
currentRecord.setValue({
fieldId:'paymentmethod',
value : ''
});
return false;
}
}
}
}
catch(err)
{
console.log("error@validateField",err)
}
return true;
}
return {
pageInit: pageInit,
validateField: validateField,
};
});