Update the class field in Invoice based on the customer selected.

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

  1. Create a custom field on Customer records.
  2. Assign a Class on the Customer record using the created custom field.
  3. Create client Script.
  4. 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
		});
	}
}

Leave a comment

Your email address will not be published. Required fields are marked *