2

Is it possible to create an invoice using item's external id and not internal id using a Restlet? I can accomplish this in Postman like this:

 "item": {
        "items": [

            { 
                "amount": 120.0,
                "item": {
                    "externalid": "12878"
                },
                 "taxCode": {                    
                    "id": "13"                    
                }
            }
        ]
    } 

But when I try to set the same in Restlet, it throws an error.

var currentItem = items[i];
record.selectNewLineItem('item');
record.setCurrentLineItemValue('item', 'externalid', currentItem["exId"]);
record.setCurrentLineItemValue('item', 'quantity', currentItem["quantity"]);
record.setCurrentLineItemValue('item', 'rate', currentItem["rate"]);
record.setCurrentLineItemValue('item', 'taxcode', currentItem["taxcode"]);
record.commitLineItem('item');
{"error":{"code":"INVALID_KEY_OR_REF","message":"Invalid item reference key 12878 for subsidiary 1."}}
quarks
  • 33,478
  • 73
  • 290
  • 513
raGs
  • 23
  • 4
  • Usually due to the item not being set the top subsidiary with [X] Include Children set. – Brian Sep 01 '20 at 20:03

1 Answers1

0

What you'd need to do is search for the items by external id.

var extIds = items.map(function(it){ return it.exId});
var items = nlapiSearchRecord('item', null, [
    new nlobjSearchFilter('externalid', null, 'anyof', extIds)
], [
    new nlobjSearchColumn('externalid')
]);
// check for null return and throw error
var extIdMap = {};
items.forEach(function(ref){
    extIdMap[ref.getValue('externalid')] = ref.getId();
});

//then instead of record.setCurrentLineItemValue('item', 'externalid', currentItem["exId"]);
record.setCurrentLineItemValue('item', 'item', extIdMap[currentItem["exId"]]);
bknights
  • 14,408
  • 2
  • 18
  • 31
  • Thank you, I'm currently doing a look up using the item's external id. Was wondering why is there a constraint with the restlet when there is clearly none with the REST api? – raGs Sep 03 '20 at 16:37
  • Who knows. There have always been differences between the SuiteTalk and SuiteScript data models. ExternalId did not always exist in SuiteTalk either; I'm guessing it was added due to customer demand to avoid having to search for internal ids in order to do SuiteTalk updates. – bknights Sep 03 '20 at 16:42
  • Thanks for the help. – raGs Sep 03 '20 at 21:49