Is there a way to get the record type of an item t...
# suitescript
j
Is there a way to get the record type of an item that is a list/record field on a custom record without doing a search? (In a userevent script)
l
@Jared Fraley, Can you use lookup field?
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record'], function(record) {
    function beforeSubmit(context) {
        var customRecord = context.newRecord;

        // Get the item from the custom record
        var itemId = customRecord.getValue({
            fieldId: 'custrecord_your_item_field' // Replace with your item field ID
        });

        // Use lookupField to get the record type of the item
        var itemRecordType = record.lookupField({
            type: record.Type.ITEM,
            id: itemId,
            fieldId: 'recordtype'
        });

        // Log the item record type
        log.debug('Item Record Type', itemRecordType);
    }

    return {
        beforeSubmit: beforeSubmit
    };
});
Deploy script on custom record
๐Ÿคจ 2
๐Ÿ‘€ 1
b
if by search you mean N/search, the above is an incorrectly written attempt to use a search
if you wished to avoid using points in general, then you can use another field that uses sourcing to get the type from your item list/record field
you will have to do a mapping from the text values to the actual suitescript record id since the values dont exactly match