Custom Name for Matrix Child

This method can be used to show a unique name for the matrix child items. Due to the lack of a webstore tab in NetSuite, the child item will presently display the parent’s name. Based on the matrix choice they have on their NetSuite record, this function generates names.

var STOCKABLE_ITEM_TYPES = [
    'INVENTORY_ITEM',
    'KIT_ITEM',
    'ASSEMBLY_ITEM',
    'ITEM_GROUP',
    'LOT_NUMBERED_ASSEMBLY_ITEM',
    'LOT_NUMBERED_INVENTORY_ITEM',
];

var itemLookup = undefined;
var itemType = '';
var isEmpty = false;
var typeCount = 0;


itemType = search.Type[STOCKABLE_ITEM_TYPES[typeCount]];
log.debug('itemType', itemType);

itemLookup = search.lookupFields({
    type: itemType,
    id: itemId,
    // 'parent' field as a given, then we concat new fields array 
    // but making sure 'parent' field is not duplicated
    columns: mergeStringArrays(['parent'], fields),
});


getDisplayName(itemLookup, itemId, itemType, "storedisplayname");


function getDisplayName(itemLookup, itemId, type, displayNameFld) {
    var MATRIX_SUBLIST_ID = 'matrixmach';
    var storedisplayname = itemLookup[displayNameFld];

    if (itemLookup.parent && itemLookup.parent.length > 0) {
        var matrixItem = itemLookup.parent[0].value;
        var matrix = record.load({
            type: type,
            id: matrixItem,
        });
        var lineCount = matrix.getLineCount({
            sublistId: MATRIX_SUBLIST_ID,
        });
        var fields = matrix.getSublistFields({
            sublistId: MATRIX_SUBLIST_ID,
        });

        storedisplayname = matrix.getValue(displayNameFld);

        for (var line = 0; line < lineCount; line++) {
            var matrixId = matrix.getSublistValue({
                sublistId: MATRIX_SUBLIST_ID,
                fieldId: 'mtrxid',
                line: line,
            });

            if (Number(matrixId) === Number(itemId)) {
                var fieldCount = 1;
                var key = '';
                do {
                    key = 'mtrxoption' + String(fieldCount);

                    var name = matrix.getSublistValue({
                        sublistId: MATRIX_SUBLIST_ID,
                        fieldId: key,
                        line: line,
                    });

                    if (name) storedisplayname += String(' ' + name);

                    fieldCount++;
                } while (fields.indexOf(key) !== -1);
            }
        }
    }

    return storedisplayname;
}

Leave a comment

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