Requirement
Create a pop up window on sales order Entry that says “Customer with Over Due Balance” if the customer has overdue balance no empty and greater than 0 and if the days overdue are greater than 0. The window should not prevent to enter the sales order, only informative.
Solution
The The pop up window only present at the entry of sales order record.
- That can be create,copy and edit modes.
2. Also when sales order creates from customer, from Add ->new
3. Sales order creates from oppurtunities
if SO created by Transactions->sales->enter sales order, the context is create we can use Field changed function, because in pageinint create mode the ID of customer didn’t get. So Field change function has choose.
If SO created from Customer record / opportunities (Add new list) we can use Pageinit function can be use.
Also in EDIT/COPY context Pageinit function works.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record','N/currentRecord','N/search'],
/**
* @param{record} record
*/
function(record,currentRecord,search) {
/**
* 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) {
try{
var currentRecord = scriptContext.currentRecord;
var customerId = currentRecord.getValue({fieldId: 'entity'});
var fieldLookUp = search.lookupFields({
type: search.Type.CUSTOMER,
id: customerId,
columns: ['overduebalance', 'daysoverdue']
});
var overDueBalance = fieldLookUp.overduebalance;
var daysOverDue = fieldLookUp.daysoverdue;
if(((overDueBalance!=null)&&(overDueBalance>0))&&(daysOverDue>0)){
if(confirm('Customer with Over Due Balance'+' '+overDueBalance)){
return true
}
else{
return false
}
}
}catch (e) {
log.debug("error@pageinit",e);
}
}
/**
* 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
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
try{
var currentRecord = scriptContext.currentRecord;
var fieldname = scriptContext.fieldId;
if (fieldname === 'entity'){
var customerId = currentRecord.getValue({fieldId: 'entity'});
if(customerId){
var fieldLookUp = search.lookupFields({
type: search.Type.CUSTOMER,
id: customerId,
columns: ['overduebalance', 'daysoverdue']
});
var overDueBalance = fieldLookUp.overduebalance;
var daysOverDue = fieldLookUp.daysoverdue;
//if the customer has overdue balance no empty and greater than 0 and if the days overdue are greater than 0
if(((overDueBalance!=null)&&(overDueBalance>0))&&(daysOverDue>0)) {
return confirm('Customer with Over Due Balance'+' '+overDueBalance);
}
}
}
}catch (e) {
log.debug("error@fieldchanged",e);
}
}
return {
pageInit:pageInit,
fieldChanged:fieldChanged
};
});