Operation is not supported for this type of UI Obj...
# suitescript
m
Operation is not supported for this type of UI Object. How can I get a field at the line level enabled based on a role?
Copy code
function beforeLoad(context) {
        const targetRoleId = 3;
        if (context.type === context.UserEventType.EDIT || context.type === context.UserEventType.CREATE) {
            var form = context.form;
            var targetFieldId = form.getField('custbody_vat_reclassification_je');

            const userRoleId = runtime.getCurrentUser().role;
            if (targetRoleId === userRoleId) {
                const currentRecord = context.newRecord;
                const sublistId = currentRecord.getSublist({sublistId: 'item'});
                const lineCount = currentRecord.getLineCount({sublistId: 'item'});
                for (let line = 0; line < lineCount; line++) {
                    const field = currentRecord.getSublistField({
                        sublistId: sublistId,
                        fieldId: targetFieldId,
                        line: line
                    });
                    field.updateDisplayType({
                        displayType: serverWidget.FieldDisplayType.NORMAL
                    });
                }
            }
        }}
l
Hi, Looks like here you’re getting the field object and not the field id:
Copy code
var targetFieldId = form.getField('custbody_vat_reclassification_je');
so this line doesn’t return a field Object:
Copy code
const field = currentRecord.getSublistField({
                        sublistId: sublistId,
                        fieldId: targetFieldId,
                        line: line
                    });
m
You were right, my targetfieldid was empty. I corrected this, however, I get TypeError: field.updateDisplayType is not a function. Is it possible to programmatically control the display type at the line level?
c
Check field. It is probably undefined/null
You need to use sublist.getField for sublist fields
👍 1
m
getField at the line level returns null. currentRecord.getField
l
what’s “targetFieldId” value?
it should be “sublist.getField”
also, you need to get the sublist from the form object, not currentRecord
Copy code
const sublist = form.getSublist({sublistId: 'item'});
const field = sublist.getField({id: 'custcol_xx'});
👍 1
m
That worked, many thanks
👍 1