I am struggling with this bit of SuiteScript, at o...
# suitescript
d
I am struggling with this bit of SuiteScript, at one point it was successful in updating price levels. Now it appears to not be properly updating. We have quantity discounting enabled and this is used for updating price levels that are not maintained on a % mark up
Copy code
function updateItemPriceLevelPrice(item, price, pricelevel_id) {
      var line = item.findSublistLineWithValue({ sublistId: "price", fieldId: "pricelevel", value: pricelevel_id });
      if (line >= 0 && price >= 0) {
          item.setMatrixSublistValue({sublistId: "price", fieldId: "price", column: 0, line: line, value: price});
          return true;
      }
      return false;
  }
a
If the NetSuite instance was updated or modified to use multiple currencies then your price sublist id could become price1: Example:
Copy code
.findSublistLineWithValue({
    sublistId: 'price1',
    fieldId: 'pricelevel',
    value: pPriceLevelId
});
d
I don't believe we changed to multiple currencies, however, I will attempt price1
actually
The issue isn't with finding the price
that appears to function properly with debugging to log
Copy code
item.setMatrixSublistValue({sublistId: "price", fieldId: "price", column: 0, line: line, value: price});
specifically this doesn't seem to be executing
a
This line could be changed from:
Copy code
if (line >= 0 && price >= 0) {
To: if (line !== -1) { That is the only thing that may be preventing you from setting the value.
d
probably a good change to make regardless
Copy code
let _currentRecord = require('N/currentRecord');
let _record = require('N/record');
let _search = require('N/search');
var item = _record.load({type: 'inventoryitem', id: _currentRecord.get().id, isDynamic: true});
var line = item.findSublistLineWithValue({ sublistId: "price", fieldId: "pricelevel", value: 1 });
item.setMatrixSublistValue({sublistId: "price", fieldId: "price", column: 0, line: line, value: 0.0092});
item.getMatrixSublistValue({sublistId: "price", fieldId: "price", column: 0, line: line});
This is my console test
I get nothing returned from getMatrixSublistValue
a
Test it server side, client side is not 100% reliable. You may need to commit the line after doing sublist operations in some cases.
d
@alien4u I have tested both client and server side
@alien4u I am not clear on which commit I would be using
I have done a item.save() if that is what you are asking