Any ideas why this is not working? `/**` `* @NAp...
# suitescript
j
Any ideas why this is not working?
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget', 'N/log'], (serverWidget, log) => {
function beforeLoad(context) {
if (context.type === context.UserEventType.CREATE) {
hideColumnField(context.form, 'item', 'taxcode');
}
}
function hideColumnField(formObj, item, taxcode) {
try {
const formSublist = formObj.getSublist({
id: 'item'
});
if (formSublist) {
const formField = formSublist.getField({
id: 'taxcode'
});
if (formField && typeof formField !== 'undefined' && formField !== null) {
formField.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
}
}
} catch(error) {
log.error({
title: 'Error:',
details: JSON.stringify({
item: item,
taxcode: taxcode
})
});
}
}
return {
beforeLoad: beforeLoad
};
});
a
Not sure why that particular code snipped is not working, but you should be able to hide the columna via Form Customization, a trick that worked for years is to remove the Label of the field meaning blank Label = Hidden while still available for scripts etc/
👍 1
e
It typically helps us if you define "not working". Is it just not doing the thing? Is it throwing an error?
👍 1
It seems to me that your
hideColumnField
function can be reduced to
Copy code
function hideColumnField(form) {
  form?.getSublist({ id: 'item' })?.getField({ id: 'taxcode' })?.updateDisplayType({ displayType: serverWidget.FieldDisplayType.HIDDEN })
}
Less code - specifically, fewer branching
if
statements - should be a little easier to troubleshoot
thisline 2
a
❤️ 1
the more you know 1
j
@erictgrubaugh Sorry I did not provide any context. Unfortunately, it's not working at all or doing what I plan on doing with the script which is to hide the taxcode column on sales orders when users create an order. I've also tried Edit and same result.
Nothing seems to work - I've tried even different fields at the line item level
taxcode still shows up when creating/editing a sales order
a
its mandatory, I don't think you can hide mandatory fields
👍 1
j
@Anthony OConnor I've tried with other fields for the sake of testing and it doesn't work
👍 1