/**
* Function will Add/Update the Permanent Address
* @param {Object} employeeObj
* @param {Object} createEmployeeRec
*/
const upsertPermanentAddress = (employeeObj, createEmployeeRec) => {
try {
if (!checkForParameter(employeeObj['PermanentCountry']) && !checkForParameter(employeeObj['PermanentAddress'])
&& !checkForParameter(employeeObj['PermanentState']) && !checkForParameter(employeeObj['PermanentCity'])
&& !checkForParameter(employeeObj['PermanentPinCode'])) {
log.debug("No Permanent Address found in HRIMS");
return;
}
let addressLineCount = createEmployeeRec.getLineCount("addressbook");
log.debug("Permanent addressLineCount", addressLineCount);
if (addressLineCount === 0) {
createEmployeeRec.selectNewLine({ sublistId: 'addressbook' });
} else {
let permanentAddressLine = createEmployeeRec.findSublistLineWithValue({
sublistId: 'addressbook',
fieldId: 'label',
value: "Permanent"
});
if (permanentAddressLine == -1) {
createEmployeeRec.selectLine({ sublistId: 'addressbook', line: addressLineCount });
} else {
createEmployeeRec.selectLine({ sublistId: 'addressbook', line: permanentAddressLine });
}
}
var myaddressSubrecord = createEmployeeRec.getCurrentSublistSubrecord({ sublistId: 'addressbook', fieldId: 'addressbookaddress' });
createEmployeeRec.setCurrentSublistValue({ sublistId: "addressbook", fieldId: 'label', value: "Permanent" });
myaddressSubrecord.setText({ fieldId: 'country', text: employeeObj["PermanentCountry"] });
myaddressSubrecord.setValue({ fieldId: 'zip', value: employeeObj["PermanentPinCode"] });
if (checkForParameter(employeeObj["PermanentState"])) {
netsuiteStateShortName = getStateID(employeeObj["PermanentState"]);
log.debug("upsertPermanentAddress netsuiteStateShortName", netsuiteStateShortName)
myaddressSubrecord.setValue({ fieldId: 'state', value: netsuiteStateShortName });
}
myaddressSubrecord.setValue({ fieldId: 'addr1', value: employeeObj["PermanentAddress"] });
myaddressSubrecord.setValue({ fieldId: 'city', value: employeeObj["PermanentCity"] });
createEmployeeRec.commitLine({ sublistId: 'addressbook' });
} catch (error) {
log.error("---Error @upsertPermanentAddress", error);
}
}