简体   繁体   中英

Map/reduce script not executed correctly (suitescript 2.0)

I am facing a weird problem where my code (specifically a record.save action) does not seem to be executed. The code is located in the 'reduce' phase of a suitescript 2.0 map/reduce script.

I have no clue what the cause for this might be. The logging does display 'is this executed' as stated in the example below but the lines below that do not seem to be executed. The logging does not show 'Order lines marked for order with ID:

//load the order
    var SOrecord = record.load({
        type: record.Type.SALES_ORDER,
        id: orderId,
        isDynamic: false
    });

     setLineValues(SOrecord, values, newShipmentId)

    log.debug('Is this executed?');
    
    //Save Order
    var recId = SOrecord.save({enableSourcing: false, ignoreMandatoryFields: true});
    
    log.debug('Order lines marked for order with ID: ', recId)
    
    return recId;

Can anyone help?

UPDATE

//load the order
    var SOrecord = record.load({
        type: record.Type.SALES_ORDER,
        id: orderId,
        isDynamic: false
    });

    log.debug('Order Loaded! ', SOrecord);
    //Loop lines present in values array
    for(var i = 0; i < values.length; i++){
        //Generate Shipment Line ID, 3 digits starting at 001
        var tmpShipmentLineId = i + 1
        var shipmentLineId = tmpShipmentLineId.toString().padStart(3, '0');
        log.debug('Shipment Line ID: ', shipmentLineId)
        //check if first fulfillment is done, if yes mark ready for second fulfillment
        if(SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) == true){
            log.debug('Line: ' + i, 'Mark ready for 2nd fulfillment')
            //Set values
             SOrecord.setSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_send_to_ff_2nd',
                line: Number(values[i]),
                value: true
            });
              SOrecord.setSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_shipment_id_2nd',
                line: Number(values[i]),
                value: newShipmentId
            });
              SOrecord.setSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_shipment_line_id_2nd',
                line: Number(values[i]),
                value: shipmentLineId
            });

        }
    //If not, mark ready for first fulfillment
        else{
            log.debug('Line: ' + i, 'Mark ready for first fulfillment')
            //Set Values
             SOrecord.setSublistValue({
               sublistId: 'item',
               fieldId: 'custcol_il_send_ff_interface',
               line: Number(values[i]),
               value: true
            });
            SOrecord.setSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_shipment_id',
                line: Number(values[i]),
                value: shipmentId
            });
            SOrecord.setSublistValue({
                sublistId: 'item',
                fieldId: 'custcol_shipment_line_id',
                line: Number(values[i]),
                value: shipmentLineId
            });

        }   

    };

    log.debug('SOrecord after changes: ', SOrecord);

    SOrecord.save();

    log.debug('Record Saved ', 'END');

Above you'll find an extended code snippet, for some reason all code outside of the for loop does not seem to be executed... Any ideas?

First of all, thanks for the help:). I've solved the problem, the last setSublistValue failed. I was not aware of this because I did not add a try/catch statement...

Thanks again for the fast response

I'm not sure I understand the setup of the code here... the text refers to the first code snippet but the second one seems more informative. Here are some general things I would try but if you clarify what is printing and what is not on the second code snippet maybe I can help more...

(1) Add a try catch for better error handling. You seem to be getting a error that's not being logged.

(2) Try loading the record in dynamic mode and using selectLine -> setCurrentSublistValue -> commitLine

(3) it seems you are using "line: values:[i]" I don't have a example of what that returns but it seems it should be "line: i"

(4) have you logged this - SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) - if not please do and let us know what the value is...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM