I'm getting an error "Invalid reference key [-1]."...
# suitescript
c
I'm getting an error "Invalid reference key [-1]." when trying to add an item to a purchase order. The item exists, is not inactive, and can be added to a purchase order in the UI without issue. Anyone have any ideas?
Copy code
r.setCurrentSublistValue({
  sublistId: 'item',
  fieldId: 'item',
  value: '37984'
});
s
are you sure the error is due to adding item?
👀 1
c
This is what the stack trace points to
According to ask-stanley, the error indicates an issue with the item, either it doesnt exist, is inactive, or there's a configuration issue with the item, but I already have a script that is able to successfully add this item to sales orders. The script is also set to run as admin.
setCurrentSublistText isn't working either
Other items work fine, I'll chalk this up to an issue with the item
s
adding other item is working with same code?
c
Yeah, changing the value to an internalid of a different item works
c
@Corey Schwoebel Could there be an issue with a line field that should be sourced from the item record to the transaction line?
s
it might be the vendor problem
some items might be set as vendor specific
c
holy crap, im not setting the vendor on the PO, lol
I figured im doing somethign stupid, let me try setting the vendor and see how it shakes out
s
please try with the vendor who is the item's preferred vendor
c
Well, it cleared up some other odd behavior, but the item is still pulling the same error. Here's the function that creates the PO(i've changed the item value to one that works for now):
Copy code
function createPos(data) {

				for (const invoice in data) {
					log.debug({title: 'invoice data', details: data})
					var r = record.create({
						type: record.Type.PURCHASE_ORDER,
						isDynamic: true
					})
					r.setValue({
						fieldId: 'entity',
						fieldId: 11517
					})
					r.setValue({
						fieldId: 'duedate',
						value: format.parse({value: new Date(data[invoice].dueDate), type: format.Type.DATE})
					})
					r.setValue({
						fieldId: 'memo',
						value: 'Invoice# ' + invoice
					})
					r.setValue({
						fieldId: 'location',
						value: data[invoice].location
					})
					r.setValue({
						fieldId: 'class',
						value: 8
					})
					r.setValue({
						fieldId: 'custbody_inbound_shipping_method',
						value: data[invoice].shipMethod
					})
					r.setValue({
						fieldId: 'custbody7',
						value: true
					})
					for (var j = 0; j < data[invoice].items.length; j++) {

						r.selectNewLine({
							sublistId: 'item'
						})
						r.setCurrentSublistValue({
							sublistId: 'item',
							fieldId: 'item',
							value: 9482
						});
						r.setCurrentSublistValue({
							sublistId: 'item',
							fieldId: 'description',
							value: data[invoice].items[j].description
						});
						r.setCurrentSublistValue({
							sublistId: 'item',
							fieldId: 'quantity',
							value: data[invoice].items[j].units
						});
						r.setCurrentSublistValue({
							sublistId: 'item',
							fieldId: 'rate',
							value: data[invoice].items[j].costPrice
						});
						r.commitLine({
							sublistId: 'item'
						})

					}
					r.save()
				}
			};
The item has this vendor listed as its only vendor, though it's not marked preferred.
c
Any location / subsidiary / department or other restrictions at play here?
👍 1
c
It's a schedule script set to run as admin, so I can't imagine there would be.
c
@Corey Schwoebel I mean a conflict between those categories on the item and those on the vendor / po
c
Not that im aware of, using a different vendor produces the same results
g
I second Clay on this one. When I've run into this it's usually been an item that isn't set up for the subsidiary, location, class, department, or account that the transaction is using.
Oh, is this item set up as a purchase item?
it might only be available for sale
b
a quick look suggests you are using format.parse wrong
not that it should give you your error
use Field.getSelectOptions to confirm that your item is a valid select option
c
Turns out the issue was the vendor price was set to 0.00 on the item record. Changing it to 0.01 allowed me to use the item in the script.
102 Views