Description:
The goal is to add an editable custom sublist field in the Assembly Item record, which initially seemed not directly possible. To achieve It involved creating a custom record and custom field to serve as storage for the value entered by the user in the custom sublist field. When the user inputs a value in the custom sublist field on the Assembly Item record, it gets stored in the corresponding custom record and field.
Code:
function beforeLoad(context) {
try {
if (context.type === context.UserEventType.EDIT || context.type === context.UserEventType.VIEW) {
var assemblyRecord = context.form;
var componentsSublist = assemblyRecord.getSublist({ id: 'member' });
// Add a new custom field called "custcol_custom_field" of type "text" to the Components sublist
var customField = componentsSublist.addField({
id: 'custpage_field',
type: serverWidget.FieldType.TEXT,
label: 'description2'
});
context.newRecord.setSublistValue({
sublistId: 'member',
fieldId: 'custpage_field',
line: 0,
value: null
});
context.newRecord.setSublistValue({
sublistId: 'member',
fieldId: 'custpage_field',
line: 1,
value: null
});
customField.defaultValue = "memo";
}
} catch (error) {
log.error(error.message)
}
// Add your custom line field here
}
function afterSubmit(context) {
var newRecord = context.newRecord;
var customFieldValue = newRecord.getSublistValue({
sublistId: 'member',
fieldId: 'custpage_field',
line: 0
});
log.debug("custom filed value is:",customFieldValue);
var customRecord = record.load({
type: 'customrecordjj_cus_assembly',
id:149
});
customRecord.setValue({ fieldId: 'custrecordjj_customfield', value:customFieldValue });
var newVal=customRecord.getValue({ fieldId: 'custrecordjj_customfield' });
log.debug(newVal);
customRecord.save();
var val =context.newRecord.setSublistValue({
sublistId: 'member',
fieldId: 'custpage_field',
line: 0,
value: newVal
});
customFieldValue.defaultValue = "newVal";
log.debug(val);
}
return { beforeLoad: beforeLoad,
afterSubmit: afterSubmit
};
});