Is there something like `getRecordType()` in SS2.0...
# suitescript
j
Is there something like
getRecordType()
in SS2.0? I’m having a hell of a time working with records that could have multiple types. They’re all items, but some could be assembly items, some could be inventory, some could be kits, etc. Is there a way to determine a record’s type if you don’t already know it?
e
context.newRecord.type
j
@eblackey That works fine for the record I’m working on, but I’m in a situation where I’m trying to perform actions on a record that is associated to the current record. I can retrieve the ID of that record, but I can’t seem to do anything if I don’t know the record type (which is not always consistent)
s
I'm assuming it's some type of transaction or entity ?
j
@scottvonduhn No. Both records are items. The top level is almost always an inventory item (for now), but the associated record can either be inventory, assembly or kit
s
ah, okay
d
you can do:
Copy code
search.lookupFields({ id : XXXXX, type : search.Type.ITEM, columns : 'recordtype' })
which will give you the true 'recordtype' value if you then need to use it elsewhere to load the record by Type etc.
✔️ 1
j
Is something like this as janky as I suspect that it is?
Copy code
function getAssociatedItem(assID) {
	try {
		var associatedItem = nRecord.load({
			type: nRecord.Type.INVENTORY_ITEM,
			id: assID,
			isDynamic: true
		});
		return associatedItem;
	}
	try {
		var associatedItem = nRecord.load({
			type: nRecord.Type.ASSEMBLY_ITEM,
			id: assID,
			isDynamic: true
		});
		return associatedItem;
	}
	try {
		var associatedItem = nRecord.load({
			type: nRecord.Type.KIT_ITEM,
			id: assID,
			isDynamic: true
		});
		return associatedItem;
	}
}
s
Basically, I was going to suggest the same as @dbarnett, use search.lookupFields, or run a query with the N/query module to get the item record type.
Do you actually need to load the item record (to make changes), or do you just need to get certain field values from it?
j
The lookupFields is probably the option. It only uses 1 unit of governance. I can live with that. I’m syncing data between the two records, so actions on the associated record will only execute if the parent record has changed.
@scottvonduhn Although, there is a part where it would be beneficial to get certain field values from a record…
s
yeah, lookupFields is the cheapest option, so long as you know the internal id, and there is a search.Type enum, for what you need
👍 1
c
If there's more than 1 or an X amount of items, i'd use a search for sure using recordtype. I dunno why they made type and recordtype 2 different things but its annoying.
j
And neither of them return the actual enum that I need… 🙄