Jira Code: ME-174
For the addresses, the state name is showing only the state code but the full state name is required to show on the ‘bill to’ and ‘ship to’ address. For this added a custom field in address record and map the state name from the standard state name field and replace the code with the full state name.
User Event
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Mangalam
* ME-174
* State in Address
*************************************************************************
* Date : 29-04-2019
*
* Author:Jobin and Jismi IT services LLP
* Script Description : State in address
* Date created : 29-04-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${29-04-2019} nd :marg created
*
*
*
******************************************************************************/
define(['N/record', 'N/search','N/error'],
function(record, search,error) {
function afterSubmit(scriptContext) {
try {
var customerRec = scriptContext.newRecord.id;
var recType = scriptContext.newRecord.type;
log.debug('customerRec',customerRec)
log.debug('recType',recType)
var loadRec = record.load({
type:recType,
id: customerRec,
isDynamic: true
});
var numLines = loadRec.getLineCount({
sublistId: 'addressbook'
});
for(i=0;i<numLines; i++){
var subrec = loadRec.selectLine({
sublistId: 'addressbook',
line: i
});
var objSubrecord = loadRec.getCurrentSublistSubrecord({
sublistId: 'addressbook',
fieldId: 'addressbookaddress'
});
var state = objSubrecord.getValue('state');
var stateValue = state.split("-")
stateValue = stateValue[1]
statename = { };
statename.AN = "Andaman & Nicobar Islands";
statename.AD = "Andhra Pradesh";
statename.AR = "Arunachal Pradesh";
statename.AS = "Assam";
statename.BR = "Bihar";
statename.CH = "Chandigarh";
statename.CG = "Chhattisgarh";
statename.DN = "Dadra & Nagar Haveli";
statename.DD = "Daman & Diu";
statename.DL = "Delhi";
statename.GA = "Goa";
statename.GJ = "Gujarat";
statename.HR = "Haryana";
statename.HP = "Himachal Pradesh";
statename.JK = "Jammu & Kashmir";
statename.JH = "Jharkhand";
statename.KA = "Karnataka";
statename.KL = "Kerala";
statename.LD = "Lakshdweep";
statename.MP = "Madhya Pradesh";
statename.MH = "Maharashtra";
statename.MN = "Manipur";
statename.ML = "Meghalaya";
statename.MZ = "Mizoram";
statename.NL = "Nagaland";
statename.OD = "Odisha";
statename.OC = "Other Countries";
statename.OT = "Other Territory";
statename.PY = "Puducherry";
statename.PB = "Punjab";
statename.RJ = "Rajasthan";
statename.SK = "Sikkim";
statename.TN = "Tamil Nadu";
statename.TS = "Telangana";
statename.TR = "Tripura";
statename.UP = "Uttar Pradesh";
statename.UK = "Uttarakhand";
statename.WB = "West Bengal";
var stateText = objSubrecord.setValue({
fieldId: 'custrecord_jj_state_full_name',
value: statename[stateValue]
});
//subrec.commitSubrecord('addressbook');
loadRec.commitLine({
sublistId: 'addressbook'
});
}
var recordID = loadRec.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
}
catch (e) {
log.debug('error', e.message)
}
}
return {
afterSubmit: afterSubmit
};
});