I have a client script that I attached to an addre...
# suitescript
m
I have a client script that I attached to an address form via the “Custom Code” tab. It’s working for me, but it doesn’t work for anyone else on the address form. Any insights?
watching following 1
e
Following
n
Is there only one address form? Typically there are multiple address form based on the country selected.
thisline 1
a
is it in testing mode?
testing mode only runs for the script owner
image.png
e
It's not a Record script, but a Form script, attached via the Custom Code on the Address Form
a
oh right, sorry ignore me 😄
😂 1
e
My best guess is that the user(s) have the old Address Form cached, so clearing their browser cache might do it.
m
Nope. Tried it with an employee on zoom. They had the right form. The custom field was showing but the script didn’t do anything when they filled out the zip code.
I even tried creating a dummy user for myself. It still worked for me but not for anyone else.
e
What does the Client Script code look like? I'd have the users clear their browser cache, then I'd add a
pageInit
handler that logs a message to the console or displays right away. You can use that message to confirm whether the Client Script is loading at all. If it is, then you can proceed to troubleshoot your code. If it's not, you might need NetSuite support.
m
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/record'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
*/
function(currentRecord, record) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(context) {
var addRec = context.currentRecord;
var addState = addRec.getField({
fieldId: 'state'
});
var addSatateDisplay = addState.isDisabled = true;
//get
}
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(context) {
var addRec = context.currentRecord;
if(context.fieldId == 'zip'){
var custState = addRec.getText({
fieldId: 'state'
})
var custZip = addRec.getText({
fieldId: 'zip'
})
if(custZip === null || custZip === '') {
addRec.setValue({
fieldId:'custrecord_ace_custom_state',
value:null
});
addRec.setValue({
fieldId:'state',
value:null
});
addRec.setValue({
fieldId:'city',
value:null
});
}
else if (custZip != '') {
addRec.setText({
fieldId:'custrecord_ace_custom_state',
text:custState
});
}
}
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged
};
});
a
you're trying to set custState in the else if but its only defined in the if?
e
Nothing's obviously wrong to me, but I'd add an alert or log message right at the front of
pageInit
and use it as stated previously
m
If it’s in a custom code, I don’t know how I get a log message.
e
Browser console using
console.log()
a
just console.log (x) and hit F12 to see the logs
☝️ 1
m
Oh
@Anthony OConnor Yeah. So to prevent users from messing up the zip code, they had me hide the main state field, add a custom state field, and then that gets filled with whatever state abbreviation. There’s a custom message underneath that says to check the zip code for an error because the custom field was not filled in. Basically, a user occasionally fatfingers a zip code and submits without a state.
a
yeah that's all fine... but this code
var custState = addRec.getText({
fieldId: 'state'
})
is only in the if block of code so its not defined in the else if block
oh ffs n/m the indenting is off, its a nested if
ignore me again 😄
m
These are the coding jobs I can’t stand….covering for user stupidity. Really…just check you’ve entered the right zip and that the state is filled in.
If I could only disable the main state field but… var addSatateDisplay = addState.isDisabled = true; doesn’t work on this field.
a
idk if its worth the effort, probably not, but you could not use the address form at all, have a suitelet generate a custom form with the fields you want/need, do all your validation on there however you like, and then once its clean you have your suitelet POST handle setting the values back to the address record.
m
Oh hell no!
😂 1
a
that's a totally reasonable response
😆 1
e
On the custom form definition, you can at least make the State filed(s) mandatory; doesn't solve your Zip problem, but keeps them from submitting with an empty state
m
@erictgrubaugh That’s what i was thinking.
e
and gives you a little less code to write