Automate the sublist update.When there is a change in the body fields Season, category or sub category. We will add a new line into the customer category history sublist.In the before record submit, we can check whether the old field value and new field value has changed or not. If changed add new line to the sublist with the current season, category and sub category field value.The ‘from date’ will be today’s date.When creating the lead record the from date will be the created record date. Leave the ‘to date’ blank in both create and update case.Check whether the ‘from date’ is before or equal to the ‘to date’. From date<=To date.
ClientScript
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* Customer category History- Update customer category history sublist update.
*
*/
/*******************************************************************************
* HR Path
* **************************************************************************
*
* Date: 13/06/2019
*
* Author: Jobin & Jismi IT Services LLP
*
*
* REVISION HISTORY
*
* Revision 1 $ 13/06/2019 Maria: Create
*
******************************************************************************/
define(['N/record','N/search','N/runtime'],
function(record,search,runtime) {
function pageInit(scriptContext) {
}
function fieldChanged(scriptContext) {
try{
var currentRec = scriptContext.currentRecord;
//To trigger the field chage of the field To date
if(scriptContext.fieldId=='custrecord_hpath_8_to_date'){
//Getting the sublist
var categorySublist = currentRec.getSublist({
sublistId:'recmachcustrecord_hpath_8_parent'
});
// Get the field value From date
var fromDate = currentRec.getCurrentSublistText({
sublistId: 'recmachcustrecord_hpath_8_parent',
fieldId : 'custrecord_hpath_8_from_date'
});
var from_date = new Date(fromDate).getTime();
// Get the field value To date
var toDate = currentRec.getCurrentSublistText({
sublistId: 'recmachcustrecord_hpath_8_parent',
fieldId : 'custrecord_hpath_8_to_date'
});
var to_date = new Date(toDate).getTime();
if((fromDate) && (toDate)){
if(from_date > to_date){
alert("TO DATE should be greater than or equal to FROM DATE");
}
}
}
}catch (e) {
console.log("error@fieldChanged", getError(e));
}
}
/*******************************************************************************
* return error
* Created on 13-June-2019 by Maria
*/
function getError(e) {
var stErrMsg = '';
if (e.getDetails != undefined) {
stErrMsg = '_' + e.getCode() + '<br>' + e.getDetails() + '<br>'
+ e.getStackTrace();
} else {
stErrMsg = '_' + e.toString();
}
return stErrMsg;
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged
};
});