/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/runtime','N/ui/serverWidget'],
(runtime, serverWidget) => {
const TOKEN_PARAM_ID = 'custscript_google_map_token';
const ADDRESS_FIELDS = ['addr1','addr2','city','state', 'zip','country'];
const beforeLoad = (scriptContext) => {
try {
if (scriptContext.type === scriptContext.UserEventType.VIEW){
let token = runtime.getCurrentScript().getParameter(TOKEN_PARAM_ID);
log.debug('url', 'https://www.google.com/maps/embed/v1/place?key=${token}${getFormatedAddress(scriptContext.newRecord)}');
log.debug('token', token)
var googleMapField = scriptContext.form.addField({
id: 'custpage_googlemap',
label: 'Google Map',
type: serverWidget.FieldType.INLINEHTML
});
googleMapField.defaultValue = '<iframe width="600" height="450" style="border:0" loading="lazy" allowfullscreen ' +
'referrerpolicy="no-referrer-when-downgrade" ' +
`src="https://www.google.com/maps/embed/v1/place?key=${token}${getFormatedAddress(scriptContext.newRecord)}">` +
'</iframe>';
}
}catch(e){
log.error('beforeLoad',e);
}
}
const getFormatedAddress = (recordCustomer) => {
try {
let intLineNum = recordCustomer.findSublistLineWithValue({
sublistId: 'addressbook',
fieldId: 'defaultshipping',
value: true,
});
if (intLineNum != -1){
let recAddress = recordCustomer.getSublistSubrecord({
sublistId: 'addressbook',
fieldId: 'addressbookaddress',
line: intLineNum
});
let addressText = ADDRESS_FIELDS.map(x=>{return recAddress.getValue(x)}).filter(y=>{return y.length>0}).join('+');
log.debug('address', `&q=${addressText}`)
return `&q=${addressText}`
}
}catch(e){
log.error('getArrayAddress',e);
}
}
return {beforeLoad}
});
Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.
We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!
It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –