RE: How to hide sublist fields in beforeload in SuiteScript 2.0 of current record?
Answered
The below code gives the following error : ‘
TypeError: Cannot find function updateDisplayType in object standard record. |
define(['N/record', 'N/log', 'N/search', 'N/task', 'N/ui/serverWidget'], function(record, log, search, task, serverWidget) { function beforeLoad(scriptContext) { log.audit('In before laod UE'); if (scriptContext.type == 'create' || scriptContext.type == 'copy') { var currentRecord = scriptContext.newRecord; var deliItem = currentRecord.setSublistValue({ sublistId: 'recmachcustrecord_rent_rod_delivery_note', fieldId: 'custrecord_rent_rod_delivered_item', line: 0, value: 400 }); deliItem.updateDisplayType({ displayType: serverWidget.FieldDisplayType.HIDDEN }); } } return { beforeLoad: beforeLoad }; });
Best answer
You are confusing the record and form objects. Record.setSublistValue returns a record.Record, which does not have a updateDisplayType method.
Use scriptContext.form to access the serverWidget.Form, then get the serverWidget.Sublist, then get the serverWidget.Field. Then you can use updateDisplayType on the Field.