<@U016TC4RJ3C> Would you mind to share some of the...
# suitescript
a
@Diderik Would you mind to share some of the code that is not working?
d
This is the code
Copy code
//Arbitrary rate
const rate = 123;

// Its the last item on the transaction
const lineCount = currentRecord.getLineCount({ sublistId: "item" });
currentRecord.selectLine({ sublistId: "item", line: lineCount - 1 });

currentRecord.setCurrentSublistValue({
  sublistId: "item",
  fieldId: "rate",
  value: rate,
});

currentRecord.commitLine({ sublistId: "item" });
a
To be able to change the line rate in most transactions you need to first set the price level to custom: fieldId: “price”, value: -1
🎉 1
And then you set the rate and commit the line…
d
Ah thats interesting, I will try that. Thanks!
Setting the price level doesn't "stick" for some reason. I use
setCurrentSublistValue
to set it, but it stays the same price level. If use
getCurrentSublistValue
immediately after to get the price level it gives me an empty string.
a
Copy code
.setSublistValue({
    sublistId: 'item',
    fieldId: 'price',
    value: '-1'
});
My bad is an string ^^^
@Diderik ^^^
d
Thanks! After a bid of fiddling I got it to work, albeit in a vacuum of sorts. The use case I have for this is having a checkbox that triggers a fieldChanged event that builds the BOM based on some info the users have filled in. In some cases however the rate changes based on the quantity of the item. So while adding all the items I want to change the rate. If I execute the code then, I still get the error I mentioned. But if I execute the code in a different fieldChanged event after all the items have been added it does work. Also why my BOM-building function is running the BOM doesn't change in the UI, only after the function has completed. And if during the function I use
findSublistLineWithValue
to get the line of the item I just added I get -1. So it feels like it can't properly access the sublist or something
Never mind, I am stupid. The item I was adding was not a single item, but an Item Group with just 1 item in it. Changing it to add that 1 item instead of the Item Group fixed it
Turns out I also don't have to change the price level. The issue was just it being an item group instead of an item