this is a client script why doesn't this code get ...
# ask-stanley-ai
n
this is a client script why doesn't this code get the inventorydetail var currLine = newRecord.selectLine({ sublistId: 'item', line: i }); var itemId = currLine.getSublistValue({ sublistId: 'item', fieldId: 'item', line: i }); log.debug({ title: "itemId", details: itemId }); if(itemId) { var itemPromoDetails = getItemPromo(itemId); if (itemPromoDetails) { var promoQty = Number(itemPromoDetails.promoQty); var giftedQty = Number(itemPromoDetails.giftedQty); var promoLot = itemPromoDetails.promoLot; log.debug({ title: "Promo Details", details: itemPromoDetails }); var itemQuantity = currLine.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i }); log.debug({ title: "itemQuantity", details: itemQuantity }); try { var invSubRec = currLine.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail' }); log.debug({ title: "invSubRec", details: invSubRec });
c
AI generated answer (using internal Slack threads):
The issue you're facing is due to the fact that the
getCurrentSublistSubrecord
method does not create a new subrecord if one does not exist. It only retrieves an existing subrecord. If the subrecord does not exist, it will return
null
. In your code, you're trying to get the
inventorydetail
subrecord from the
item
sublist. If the
inventorydetail
subrecord does not exist for the current line, the method will return
null
. To solve this issue, you need to first check if the subrecord exists using the
hasCurrentSublistSubrecord
method. If it does not exist, you can create a new subrecord using the
setCurrentSublistSubrecord
method. Here is an example of how you can modify your code:
Copy code
javascript
if (!currLine.hasCurrentSublistSubrecord({
    sublistId: 'item',
    fieldId: 'inventorydetail'
})) {
    var invSubRec = currLine.setCurrentSublistSubrecord({
        sublistId: 'item',
        fieldId: 'inventorydetail',
        subrecord: newSubrecord // replace newSubrecord with the actual subrecord you want to create
    });
} else {
    var invSubRec = currLine.getCurrentSublistSubrecord({
        sublistId: 'item',
        fieldId: 'inventorydetail'
    });
}
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.879057467
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.878351
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.875727236
Please provide your feedback on this answer.