We are creating new items via MapReduce. We are ha...
# suitescript
s
We are creating new items via MapReduce. We are having issues with setting the sale price. The only option so far that works is this (however this is slow and expensive any ideas ?
Copy code
if (salePrice) {
      const itemRecord = record.load({
        type: record.Type.INVENTORY_ITEM,
        id: newItemId,
        isDynamic: false,
      });
      itemRecord.setSublistValue({
        sublistId: "price1",
        fieldId: "price_1_",
        value: salePrice,
        line: 0,
      });
      itemRecord.save();
a
That is the only way you can do it, price is a Sublist, your other option is a CSV import in which case you could disable the execution of background scripts and workflows deployed to the Item record and that could in theory speed up the process.
n
An alternate you can use is the save.promise(). It improves performance. Otherwise, like @alien4u suggested, use CSV.
s
save.promise() would only help on the last call of the record.save meaning after price set
n
Maybe you could use the Task module to run in the CSV that Alien suggested. You presumably know what data you need to work with so it'd be simple enough (in theory) to create the CSV on the fly using papaparse or in a more manual way. As mentioned, set up the Saved CSV Import ensuring you set the flag to not trigger scripts, presuming for your needs the price change shouldn't trigger them.
b
you will also want to better explain why you are loading an item you just created. You failed to do so and received a bunch of answers thinking that saving a record is slow instead of saving a record twice is slow.
a
Good point about loading a record he just created; about the Pricing Matrix I’m not sure that one is always exposed; I believe it would depend on the features enabled on the specific instance.
s
we are using price matrix the issue i was runnig into was setting it on create , the only option i got to work was save and reload
šŸ‘šŸ» 1
b
your code is not using the price matrix
s
I'm aware of that the code using the price matrix failed if the item hasn't been saved
b
what did that code look like
and what error did you get using it