The “Entity” record type in NetSuite is a catch-all category that includes a number of more specific entity types like Vendor, Customer, Employee, Contact, Group, Partner, etc. In some cases, defining a custom field as an entity rather than a more specific type is necessary. However, when performing a lookup of the field in the script, sometimes the record type returned won’t not match expectations.
var recordTypeLookup = search.lookupFields({
type: 'entity',
id: recId,
columns: 'type'
});
var recordType = recordTypeLookup.type[0].value;
var entityRec = record.load({
type: recordType, // Fails for customers as NS expect 'Customer' here instead of 'CustJob'
id: recId
});
When a vendor record was chosen, everything went smoothly. However, after choosing a client, I encountered the following error:
“The record type [CUSTJOB] is invalid“
It turns out that CustJob instead of Customer is returned as the type for customer lookups which trips the system.
Use recordtype for the lookup rather than type!
var recordTypeLookup = search.lookupFields({
type: 'entity',
id: recId,
columns: 'recordtype'
});
var entityRec = record.load({
type: recordTypeLookup.recordtype,
id: recId
});
Note: Apparently, the customer type is called CustJob because Customers and Projects are kinda the same records.