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.
Do you have any code snippet for the same in UserEvent script in 2.0?
Documentation for getting the field is fairly clear about how the code should look. Same thing about using updateDisplayType
Thanks buddy got it.
Did something like this :
var itemField = form.getSublist({ id: 'recmachcustrecord_rent_rod_delivery_note' }).getField({ id: 'custrecord_rent_rod_delivered_item' }).updateDisplayType({ displayType: serverWidget.FieldDisplayType.HIDDEN });