I am creating an invoice via SuiteScript and when ...
# suitescript
n
I am creating an invoice via SuiteScript and when I try and hard code the costestimate field to 12 to make sure it sets a value, all of my "Non-inventory Item for Resale" item lines are not being set with 12 but the two inventory items do get set to 12. Any ideas?
Copy code
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'costestimate', value: 12 });
c
Have you tried this in the UI. I.e. manually create an invoice, add a NonInv item and set the costestimate sublist field, then successfully save?
n
No, but it was just odd it worked via suitescript on inventory items but not these so I was starting to think it was a restriction somehow.
p
Did you set the
costestimatetype
to Custom? I've built a script before for Estimate records that updates the
costestimate
, and I had to explicitly set the
costestimatetype
in order for it to work.
n
@Patrick A. no i didn't try that. Do you set it with 'custom' or is there a id that is consistent across environments?
c
@Nicholas Williams There's a Chrome extension "NetSuite Field Explorer" that will allow you to get values from records and sublists. That's how I usually lookup hard coded system values.
p
The ID is
CUSTOM
. A possible reason it works for the Inventory Item but not for the Non-Inventory Item is that the Inventory Item record has its Cost Estimate Type set to Custom, while the Non-Inventory Item does not. This setting must be explicitly defined for the script to update the
costestimate
field correctly. When you add an item to a transaction, NetSuite references the Cost Estimate Type from the item record and uses it as the default value for the line item. I suggest always use
CUSTOM
when you want to changes your
costestimate
, that way you can still set the
costestimate
even if the item's Cost Estimate Type is not
CUSTOM
.