Hey everyone, is it possible to show/hide a custom...
# suitescript
m
Hey everyone, is it possible to show/hide a custom field on an item record based on checking/unchecking a custom checkbox field? In a Client Script, I have:
function fieldChanged(context) {
if(context.fieldId === "some_checkbox_id") {
var val = context.currentRecord.getValue({ fieldId: 'some_checkbox_id' }),
el = context.currentRecord.getField({ fieldId: 'some_multiselect_id' });
// some_multiselect_id field is set to not visible in its custom item field settings
if (val = true) {
el.isDisplay = true;
} else {
el.isDisplay = false;
}
}
}
return {
fieldChanged: fieldChanged
}
b
@MR I alway found in SuiteScript 1.x that it wasn't possible/easy to display a field when the field arrived on the browser if it was hidden (either from a user event via .setDisplayType("hidden") or when a field was set to hidden at the field level). We used to set the field display type to "normal" at the field level, and then use pageInit/fieldChange triggers to conditionally hide (this does result in the fields being visible for a moment or so during page load, and then they hide during pageInit call). SuiteScript 2.x may have improved on this? Side note: the "if (val = true)" will always result in "true" as this will assign the value of "true" to val, and then read the value during the condition, not sure if this causing a red herring as the else will never run..
b
used assignment operator (=) instead of a comparison operator (== or ===) {though i would have simply used
Copy code
if (val)
otherwise code works normally
keep in mind that a field that starts out hidden cant use isDisplay to change its visibity
actually, reading @Benjamin Carson much longer answer, its what he said
m
yeah, thanks for pointing out the assignment operator, that was just a typo moving it over to Slack and not what is causing the issue... but @Benjamin Carson thanks, I will try setting it to normal and using the pageInit
thanks again @Benjamin Carson... I messed with hiding it in the pageInit and then using the fieldChanged; not ideal for what I am doing; I'll have to go with enabling/disabling.
e
Here's how you can do it...
p
This is an easy thing when you use a workflow.