Jira code: ACL-7
Once a user clicks on save button in item fulfilment record during the creation of IF record, the script or workflow will check whether the created from the record(sales order) has any invoices with ‘paid’ status for the items including this IF. If yes then no actions will take. If no invoices attached with paid status the will check in customer record whether it COD customer. If COD customer gives an alert message: want to proceed”. If yes will create the IF creation. If no the IF record will not be created. If the customer is not a COD customer no actions will be taken.
When the user will say no the IF will not be created and populated to Sales order record.
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:ACL Welding
* ACL-7 Alert when COD customer creates a IF without payment done
*************************************************************************
* Date : 05/04/2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : Alert when COD customer creates a IF without payment done
* Date created : 05/04/2019
*
* REVISION HISTORY
*
* Revision 1.0 ${05/04/2019} aj : created
*
*
******************************************************************************/
define(['N/record', 'N/search', 'N/ui/dialog','N/url'],
/**
* @param {record} record
* @param {search} search
* @param {dialog} dialog
*/
function(record, search, dialog,url) {
/**
* Validation function to be executed when record is saved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @returns {boolean} Return true if record is valid
*
* @since 2015.2
*/
function saveRecord(scriptContext) {
try{
var currentRec = scriptContext.currentRecord;
// to get the customer entity
var customer = currentRec.getValue({
fieldId:'entity'
});
// created from
var createdFrom = currentRec.getValue({
fieldId:'createdfrom'
});
var flag = true;
terms =currentRec.getText({
fieldId:'custbody3'
});
if(terms=='COD')
{
// to check SO paid fully or not
var isTrue =findAmountPaidOrNot(createdFrom);
if(isTrue=='true'|| isTrue==true)
{
var retnValue= confirm("IMPORTANT This order is an unpaid COD order. Are you sure you want to fulfill?")
if(retnValue==false)
{
var output = url.resolveRecord({
recordType: 'salesorder',
recordId:createdFrom ,
isEditMode: false
});
window.location.href = output;
}
else
return true;
}
else if(isTrue=='false'|| isTrue==false)
return true;
}
else if(terms!='COD')
return true;
}catch(e)
{
log.debug("Err@ FN saveRecord",e);
log.error("Err@ onAction FN saveRecord",e);
//console.log("Err@ FN =",e);
}
}
function findAmountPaidOrNot(createdFrom){
try{
// create a search for finding amount
var transactionSearchObj = search.create({
type: "transaction",
filters:
[
["type","anyof","CashSale","CustInvc","Deposit"],
"AND",
["mainline","is","T"],
"AND",
["createdfrom","anyof",createdFrom],
"AND",
["status","anyof","CashSale:A","CashSale:C","CustInvc:B","CustDep:C","CustDep:D","CustDep:B"]
],
columns:
[
search.createColumn({
name: "entity",
summary: "GROUP",
label: "Name"
}),
search.createColumn({
name: "amount",
summary: "SUM",
label: "Amount"
}),
search.createColumn({
name: "amount",
join: "createdFrom",
summary: "SUM",
label: "Amount"
})
]
});
var searchResultCount = transactionSearchObj.runPaged().count;
var searchResult = transactionSearchObj.run().getRange({
start:0,
end:1
});
var amountTotalPaid=0,amountInSO=0;
if(searchResultCount>0)
{
amountTotalPaid = searchResult[0].getValue({
name: "amount",
summary: "SUM",
label: "Amount"
});
amountInSO = searchResult[0].getValue({
name: "amount",
join: "createdFrom",
summary: "SUM",
label: "Amount"
});
var dueAmount = parseFloat(amountInSO)-parseFloat(amountTotalPaid);
if(dueAmount>0)
{
return true;
}
else if(dueAmount<=0)
{
return false;
}
}
if(searchResultCount<=0)
{
return true;
}
}catch(e)
{
console.log("Err@ FN findAmountPaidOrNot=",e);
}
}
return {
saveRecord: saveRecord
};
});