API for Item Description update

Jira Code: MISC-134

A NetSuite Restlet which is used to update the item record with the new item description. The authentication for the API is token based. Post request is an HTTP method to update the item description.

/*******************************************************************************
 * MISC - 134 
 * **************************************************************************
 * 
 * Date: 21-06-2018
 * 
 * Author: Jobin & Jismi IT Services LLP
 * 
 *****************************************************************************
 **/
function postGettingData(datain) {
    /*Recieve all the descriptions and item id */
    var itemId = datain.item_id;
    var itemDesc = datain.item_desc;
    var itemDetails = GetTheItemInternal(itemId);
    if (itemDetails == false) {
        var id = createRecord(itemDesc);
        var jsonObj = {
            status: false,
            recordId: id
        };
    } else {
        /*Load Record*/
        nlapiLogExecution('DEBUG', 'true ', itemDetails);
        var recordId = updateRecord(itemDesc, itemDetails.iteminternal);
        var jsonObj = {
            status: true,
            recordId: recordId,
        };
    }
    return jsonObj;
}
/*Find the Item Internal */
function GetTheItemInternal(id) {
    var itemSearch = nlapiSearchRecord("item", null, [
        ["internalidnumber", "equalto", id]
    ], [
        new nlobjSearchColumn("internalid"),
        new nlobjSearchColumn("itemid").setSort(false)
    ]);
    if (itemSearch) {
        nlapiLogExecution('DEBUG', 'itemSearch.length', itemSearch.length);
        var responseObj = {};
        responseObj.iteminternal = itemSearch[0].getValue('internalid');
        responseObj.item_name = itemSearch[0].getValue('itemid');
        return responseObj
    } else {
        return false
    }
}
/*Load Record*/
function updateRecord(descriptions, id) {
    var itemRecObj = nlapiLoadRecord('inventoryitem', id);
    itemRecObj.setFieldValue('purchasedescription', descriptions);
    var recordId = nlapiSubmitRecord(itemRecObj, false, true);
    return recordId
}
/*createrecord */
/*currently the item name is also set  description */

function createRecord(descriptions) {
    var recordObj = nlapiCreateRecord('inventoryitem');
    recordObj.setFieldValue('itemid', descriptions);
    recordObj.setFieldValue('purchasedescription', descriptions);
    var id = nlapiSubmitRecord(recordObj, true);
    return id
}

Leave a comment

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