Hi , Sorry for late Response,
I direct user Form.field.UpdateDisplayType,
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/log'], (log) => {
const beforeLoad = (context) => {
if (
context.type !== context.UserEventType.VIEW &&
context.type !== context.UserEventType.EDIT &&
context.type !== context.UserEventType.CREATE
) {
return;
}
try {
let newRecord = context.newRecord;
let form = context.form;
// 1. Ambil nilai custom field Checkbox
let staffForm = newRecord.getValue({
fieldId: 'custbody_lf_is_staff_form',
});
// Cek di Execution Log untuk memastikan tipe datanya
log.debug(
'Cek Flag Staff Form',
'Nilai custbody_lf_is_staff_form: ' +
staffForm +
' | Tipe: ' +
typeof staffForm,
);
// 2. PERBAIKAN: Gunakan boolean true, bukan string 'T'
if (staffForm === true) {
let itemSublist = form.getSublist({ id: 'item' });
if (itemSublist) {
const sublistFieldsToHide = [
'amount',
'rate',
'taxcode',
'taxrate1',
'tax1amt',
'grossamt',
'custcol_4601_witaxapplies',
'custcol_4601_witaxbaseamount',
'custcol_4601_witaxcode',
'custcol_4601_witaxrate',
'custcol_4601_witaxamount',
'custpage_4601_witaxbaseamount',
'custpage_4601_witaxamount',
];
sublistFieldsToHide.forEach((fieldId) => {
let field = itemSublist.getField({ id: fieldId });
if (field) {
field.updateDisplayType({ displayType: 'HIDDEN' });
}
});
}
const headerFieldsToHide = ['total', 'subtotal', 'taxtotal'];
headerFieldsToHide.forEach((fieldId) => {
let headerField = form.getField({ id: fieldId });
if (headerField) {
headerField.updateDisplayType({ displayType: 'HIDDEN' });
}
});
}
} catch (error) {
log.error({
title: 'Error Hiding Amount Fields on PO',
details: error.message || error,
});
}
};
return {
beforeLoad: beforeLoad,
};
});