Anyone have experience with `setMatrixSublistValue...
# suitescript
n
Anyone have experience with
setMatrixSublistValue
? I'm loading an item record and setting the MSRP using
setMatrixSublistValue
. I'm then calling
itemRecord.save()
. Is that all that I need to do or is there a matrix sublist commit or any like that?
b
depends on the features in your account
but usually yes
n
Here is what I am trying
Copy code
var priceSublistCount = itemRecord.getLineCount({ sublistId: 'price1' });
for (var priceSublistLine = 0; priceSublistLine < priceSublistCount; priceSublistLine++) {
    var selectedLine = itemRecord.selectLine({ sublistId: 'price1', line: priceSublistLine }); // Don't know if this is needed
    var selectedPriceLevel = itemRecord.getCurrentSublistValue({ sublistId: 'price1', fieldId: 'pricelevel', line: priceSublistLine });
    
    itemRecord.setMatrixSublistValue({ 
        sublistId: 'price1', 
        fieldId: 'price', 
        column: 0, 
        line: priceSublistLine,
        value: priceData[selectedPriceLevel] 
    });

    //TODO: DOES THIS WORK?
    itemRecord.commitLine({ sublistId: 'price1' });

    }
}
itemRecord.save();
b
i personally cant tell if you are using dynamic mode or standard mode
if you are using dynamic mode, you probably want to be using Record.setCurrentMatrixSublistValue
beyond that, you should probably try getting the value first to make sure you are in the right place
then you can try setting it
r
There is no "setMatrixSublistValue" in SuiteScript 2.0 APIs. You will have to use "Record.setCurrentMatrixSublistValue(options)". Note that this is used in dynamic mode only. So use
Copy code
isDynamic: true
when loading the item record. Also yes itemRecord.selectLine({ sublistId: 'price1', line: priceSublistLine }); is needed. Hope this helps. All the best!
b
r
yes, I stand corrected. Record.setMatrixSublistValue(options) is there in 2.0 APIs. Thanks @battk
n
Cleaned up Code:
Copy code
var itemRecord = recordModule.load({
    type: recordModule.Type.LOT_NUMBERED_ASSEMBLY_ITEM,
    id: productId,
    isDynamic: true
});

var priceSublistCount = itemRecord.getLineCount({ sublistId: 'price1' });

for (var priceSublistLine = 0; priceSublistLine < priceSublistCount; priceSublistLine++) {
    var selectedLine = itemRecord.selectLine({ sublistId: 'price1', line: priceSublistLine });
    var priceLevel = itemRecord.getCurrentMatrixSublistValue({ sublistId: 'price1', fieldId: 'pricelevel', column: 0 });
    log.debug('Line: ' + priceSublistLine, 'PriceLevel: ' + JSON.stringify(priceLevel));

    itemRecord.setCurrentMatrixSublistValue({ sublistId: 'price1', fieldId: 'price', column: 0, value: 0 });
    itemRecord.commitLine({ sublistId: 'price1' });
}
unfortunately I am getting an error, that does not make sense to me.
{"type":"error.SuiteScriptError","name":"SSS_METHOD_IS_ONLY_ALLOWED_FOR_MATRIX_FIELD","message":"Method is only allowed for matrix field."
NetSuite doesn't like my use of
getCurrentMatrixSublistValue
b
what does your price list look like?
which of the Pricing Sublist Feature Dependencies are enabled
n
Real quick, this works
Copy code
var priceLevel = itemRecord.getCurrentSublistValue({ sublistId: 'price1', fieldId: 'pricelevel', line: priceSublistLine }); // dynamic
We have Multiple Currencies, Multiple Prices and Quantity Pricing enabled.
This seems to work, Thanks @battk and @Raj Konds