Function to get internal ID of Stock unit in account with Multiple units of measure

/**
 * @description Function to get internal ID of the stock unit
 * @param unitname - unit name
 * @param Wine_packsize - size need to be find out
 * @returns {*number*}
 */
function getStockUnit(unitTypeInternalID, unitname, wine_packsize) {
    log.debug("unitname", unitname);
    if (checkForParameter(unitTypeInternalID)) {
        var unitRec = record.load({
            type: record.Type.UNITS_TYPE,
            id: unitTypeInternalID,
            isDynamic: false
        });
        var linecount = Number(unitRec.getLineCount({sublistId: "uom"}));
        var index = -1;
        index = unitRec.findSublistLineWithValue({sublistId: "uom", fieldId: "unitname", value: unitname})
       
        if (index > 0) {
            var internalID = unitRec.getSublistValue({fieldId: 'internalid', sublistId: "uom", line: index});
            
        } else {
            unitRec.setSublistValue({
                fieldId: 'abbreviation',
                sublistId: "uom",
                line: linecount,
                value: "Case of " + wine_packsize
            });
            unitRec.setSublistValue({
                fieldId: 'conversionrate',
                sublistId: "uom",
                line: linecount,
                value: wine_packsize.toString()
            });
            unitRec.setSublistValue({
                fieldId: 'pluralabbreviation',
                sublistId: "uom",
                line: linecount,
                value: "Case of " + wine_packsize
            });
            unitRec.setSublistValue({
                fieldId: 'pluralname',
                sublistId: "uom",
                line: linecount,
                value: "Case of " + wine_packsize
            });
            unitRec.setSublistValue({fieldId: 'unitname', sublistId: "uom", line: linecount, value: unitname});
            var internalID = unitRec.save({
                ignoreMandatoryFields: true
            });
        }
        log.debug("unitname internalID", internalID);

        if (checkForParameter(internalID)) {
            return internalID;
        } else {
            log.debug("Unit Type is not defined in the Netsuite");
            log.debug("error@createItemRecord", err);

            return false;
        }
    } else {
        return false;
    }
}

Leave a comment

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