This topic contains 1 reply, has 0 voices, and was last updated by chrisatsc 7 years, 7 months ago.

  • Author
    Posts
  • #5592 Score: 0

    chrisatsc
    • Contributions: 0
    • Level 1

    [SOLVED – Need to set customform of itemreceipt]

    Hope someone can help me with this before the dent in my forehead gets any deeper.

    I am trying to transform a Purchase Order to an Item Receipt, with the Items using Advanced Bin Management via a RESTlet. No matter what I try, on submission the transformed record returns the extremely helpful error that I am missing an “id”.

    My SuiteScript code for this is:

    Code:
    function itemReceipt(dataIn) {
    /*
    * Have to look up items by itemname.
    *
    * @param {Array} items List of items received from the cache
    * @param {String} itemname The itemname from the itemreceipt’s item list.
    * @return {Object|Null} The item object from the cache, or null if not found.
    */
    function findItemInInput(items, itemname) {
    for (var i = 0; i < items.length; ++i) { if (items[i].item_name == itemname) return items[i]; } return null; } /* * Receive an item * * @param {Object} receiptRecord The NetSuite itemreceipt from the transformation of the purchaseorder * @param {Object} receivedItem The item received from the warehouse * @param {Integer} itemIndex The index of the item in the receiptRecord */ function receiveItem(receiptRecord, receivedItem, itemIndex) { function getAssociatedBinsForLocation(itemId, locationId) { var tmpItem = nlapiLoadRecord('inventoryitem', itemId), tmpBins = tmpItem.getLineItemCount('binnumber'), associatedBins = { preferredBin : null, bins : [] }; for (var jj = 1; jj <= tmpBins; ++jj) { var binLocation = tmpItem.getLineItemValue('binnumber', 'location', jj); if (binLocation == locationId) { var binId = parseInt(tmpItem.getLineItemValue('binnumber', 'binnumber', jj), 10); associatedBins.bins.push(binId); if (tmpItem.getLineItemValue('binnumber', 'preferredbin', jj) == 'T') { associatedBins.preferredBin = binId; } } } return associatedBins; } nlapiLogExecution('DEBUG', 'ReceiveItem', receivedItem.item_name + ', quantity: ' + receivedItem.quantity); // Set to receive, and the quantity (from all bins) receiptRecord.setLineItemValue('item', 'itemreceive', itemIndex, 'T'); receiptRecord.setLineItemValue('item', 'quantity', itemIndex, receivedItem.quantity); // Add to bins here // Select the current line item receiptRecord.selectLineItem('item', itemIndex); // Get associated bins for item var associatedBins = getAssociatedBinsForLocation(receivedItem.item_id, receiptRecord.getFieldValue('location')); nlapiLogExecution('DEBUG', 'BINS for item ' + receivedItem.item_id, JSON.stringify(associatedBins)); nlapiLogExecution('DEBUG','Creating subrecord', itemIndex); // Create the inventory detail subrecord var detail = receiptRecord.createCurrentLineItemSubrecord('item', 'inventorydetail'); nlapiLogExecution('DEBUG', 'TEST', detail.getLineItemCount('inventoryassignment')); // Iterate over the bins provided for (var k = 0; k < receivedItem.bins.length; ++k) { var bin = receivedItem.bins[k]; if ( associatedBins.bins.indexOf(bin.id) === -1) { throw nlapiCreateError('SC Error', 'Item Receipt Failure; Item ' + receivedItem.item_name + ' not associated with bin ' + bin.id, true); } detail.selectNewLineItem('inventoryassignment'); detail.setCurrentLineItemValue('inventoryassignment', 'binnumber', bin.id); detail.setCurrentLineItemValue('inventoryassignment', 'quantity', bin.quantity); // Commit the new line item to the subrecord detail.commitLineItem('inventoryassignment'); } // Commit the subrecord detail.commit(); // Commit the line item receiptRecord.commitLineItem('item'); } function getItemsReceived(receivedItems) { var item = null; receivedItems.forEach(function(receivedItem) { item = nlapiLoadRecord('inventoryitem', receivedItem.item_id); receivedItem.item_name = item.getFieldValue('itemid'); }); return receivedItems; } try { // Transform the purchaseorder record to an itemreceipt record. // By default this will mark all attached items as received, so // we need to make modifications to the item list. var receiptRecord = nlapiTransformRecord('purchaseorder', dataIn.po_id, 'itemreceipt'); var receivedItems = getItemsReceived(dataIn.items); // Iterate over the receipt's item list. var itemCount = receiptRecord.getLineItemCount('item'); for (var j = 1; j <= itemCount; ++j) { // We can only do by-name lookups between the receipt record and the data // received by the cache. var localItemName = receiptRecord.getLineItemValue('item', 'itemname', j); var receivedItem = findItemInInput(receivedItems, localItemName); if ( ! receivedItem ) { // Looks like we didn't receive this item, so toggle its // itemreceive member to false. receiptRecord.setLineItemValue('item', 'itemreceive', j, 'F'); } else { // Found the item in the data from the cache, so // receive it into the bins provided. receiveItem(receiptRecord, receivedItem, j); } } if (dataIn.memo) { receiptRecord.setFieldValue('memo', dataIn.memo); } nlapiLogExecution('DEBUG', 'SUBMIT', JSON.stringify(receiptRecord)); var itemReceiptId = nlapiSubmitRecord(receiptRecord, true); var poRecord = nlapiLoadRecord('purchaseorder', dataIn.po_id); var data = { "po_id" : dataIn.po_id, "po_status" : poRecord.getFieldValue('status') }; return netsuiteSuccess(data); } catch (e) { nlapiLogExecution('ERROR', 'Item Receipt Error', e.message); return netsuiteError(e.message); } } The stringified receiptRecord being submitted is Code: { "createddate": "1/25/2017 9:00 am", "createdfrom": { "internalid": "267763", "name": "Purchase Order #PO60639" }, "currency": { "internalid": "1", "name": "US Dollar" }, "currencyname": "US Dollar", "entity": { "internalid": "64155", "name": "V2505 CDW" }, "exchangerate": 1, "item": [ { "currency": "US Dollar", "description": "Cat5e Green 10 Foot Patch Cable", "inventorydetail": { "inventoryassignment": [ { "binnumber": { "internalid": "980", "name": "000F03A010A" }, "quantity": 10 } ], "item": { "internalid": "2191", "name": "CAT5E-GREEN-10FT" }, "quantity": 10 }, "itemname": "CAT5E-GREEN-10FT", "itemreceive": true, "itemtype": "InvtPart", "location": { "internalid": "14", "name": "DF-CH1" }, "onhand": 404, "options": { "custcol3": { "internalid": "2", "name": "Green" }, "custcol4": { "internalid": "33", "name": "10 FT" } }, "quantity": 10, "quantityremainingdisplay": 10, "rate": 1.19, "vendorname": "CAT5E-GREEN-10FT" }, { "currency": "US Dollar", "description": "Cat5e Blue 10 Foot Patch Cable", "itemname": "CAT5E-BLUE-10FT", "itemreceive": false, "itemtype": "InvtPart", "location": { "internalid": "14", "name": "DF-CH1" }, "onhand": 224, "options": { "custcol3": { "internalid": "1", "name": "Blue" }, "custcol4": { "internalid": "33", "name": "10 FT" } }, "quantity": 4, "quantityremainingdisplay": 4, "rate": 1.19, "vendorname": "CAT5E-BLUE-10FT" } ], "landedcostmethod": { "internalid": "WEIGHT", "name": "Weight" }, "landedcostperline": false, "landedcostsource1": { "internalid": "MANUAL", "name": "Manual" }, "landedcostsource2": { "internalid": "MANUAL", "name": "Manual" }, "landedcostsource3": { "internalid": "MANUAL", "name": "Manual" }, "lastmodifieddate": "1/25/2017 10:58 am", "memo": "This is a test", "postingperiod": { "internalid": "238", "name": "Jan 2017" }, "recordtype": "itemreceipt", "subsidiary": { "internalid": "2", "name": "ServerCentral" }, "trandate": "1/27/2017", "tranid": "To Be Generated" } Note that this is a partial receipt of one item for a PO with two items.
    This is a cached copy. Click here to see the original post.

  • #5593 Score: 0

    chrisatsc
    • Contributions: 0
    • Level 1

    And of course I figured it out after posting, but not after spending DAYS on trying to do so.

    Need to set the customform of the itemreceipt prior to submission, even though it’s not a customform. I think I’ve been bitten by this in the past as well. Sigh.

You must be logged in to reply to this topic.