Unable to update purchase price via Suitescript 2.x

  Kiến thức lập trình

I am currently trying to make a button on purchase orders which will allow the users to update the purchase price of a Lot Numbered Inventory Item easily. This button will call the below function with the expected parameters. The values are all expected values and output the expected values but there doesn’t appear to be a difference in the value on the LNIT record.

    function updatePurchasePrice(itemID, vendor, purchasePrice) {
        log.debug("Update Purchase Price", "Started");
        try {
            // Load the item record
            var itemRecord = record.load({
                type: record.Type.LOT_NUMBERED_INVENTORY_ITEM, 
                id: itemID,
                isDynamic: true
            });
    
            // Get the line count for the itemvendor sublist
            var lineCount = itemRecord.getLineCount({
                sublistId: 'itemvendor'
            });
    
            // Iterate through the itemvendor sublist
            for (var i = 0; i < lineCount; i++) {
                log.debug("Line Number", i);
    
                // Get the vendor at the current line
                itemRecord.selectLine({
                    sublistId: 'itemvendor',
                    line: i
                });
    
                var currentVendor = itemRecord.getCurrentSublistValue({
                    sublistId: 'itemvendor',
                    fieldId: 'vendor'
                });
    
                // Check if this is the vendor we want to update
                if (currentVendor == vendor) {
                    log.debug("Vendor Found", vendor);
    
                    itemRecord.setCurrentSublistValue({
                        sublistId: 'itemvendor',
                        fieldId: 'purchaseprice',
                        value: purchasePrice
                    });
                    log.debug("After setting purchaseprice", purchasePrice);
    
                    itemRecord.setCurrentSublistValue({
                        sublistId: 'itemvendor',
                        fieldId: 'vendorprices',
                        value: 'USA: ' + purchasePrice
                    });
                    log.debug("After setting vendorprices", 'USA: ' + purchasePrice);
    
                    itemRecord.commitLine({
                        sublistId: 'itemvendor'
                    });
                    log.debug("Committed line", i);
    
                    // Save the changes to the record
                    var saveId = itemRecord.save({
                        enableSourcing: false,
                        ignoreMandatoryFields: true
                    });
    
                    log.debug("Record Saved", "Record ID: " + saveId);
                    break; // Exit the loop once we've updated the correct vendor
                }
            }
        } catch (e) {
            log.error({
                title: 'Error updating purchase price',
                details: e.toString()
            });
        }
    }

Screenshot for aid: The below screenshot shows the record I’m trying to edit. Possibly relevant information: When editing the purchase price via the UI, a popup shows up to have me select the currency and purchase price.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT