Automatically update the Class field in a invoice whenever the Customer field is changed. A custom field has to be created in customer since customer record does not have a standard class field.Client scripts can then be used to reference the custom field after selecting a Customer record during data entry/update.
Solution
- Create a custom field on Customer records.
- Assign a Class on the Customer record using the created custom field.
- Create client Script.
- In the Post sourcing function enter the following code.
function postSourcing(scriptContext) {
var curRec = scriptContext.currentRecord;
if (scriptContext.fieldId == 'entity') {
var id = curRec.getValue({
fieldId: 'entity'
});
var custClass = search.lookupFields({
type: search.Type.CUSTOMER,
id: id,
columns: ['custentity']
})
curRec.setValue({
fieldId: 'class',
value: custClass
});
}
}