RE: How to load and save work order record using map reduce script?

I am trying to load and save work order record usingĀ  map reduce script. But after executing, I am not getting logs for load object and save object.Please Help!

Below is my code:

 function getInputData(){
    var process_data =[];
        try{
            var workorderSearchObj = search.create({
               type: "workorder",
               filters:
               [
                  ["type","anyof","WorkOrd"], 
                  "AND", 
                  ["mainline","is","T"], 
                  "AND", 
                  ["status","anyof","WorkOrd:A","WorkOrd:B","WorkOrd:D"]
               ],
               columns:
               [
                  search.createColumn({name: "internalid", label: "Internal ID"}),
                  search.createColumn({name: "tranid", label: "Document Number"})
               ]
            });
            var searchResultCount = workorderSearchObj.runPaged().count;
            log.debug("workorderSearchObj result count",searchResultCount);
            workorderSearchObj.run().each(function(result){
               // .run().each has a limit of 4,000 results
               var work_Order = result.getValue({name:'internalid'});
               var document_no = result.getValue({name:'tranid'});
               process_data.push({
                'work_Order':work_Order,
                'document_no':document_no
            });
               return true;
            });
            
        
        }catch(error){
            log.debug(error);
        }   
            return process_data;
    }
     function map(context){
        var process_data=JSON.parse(context.value);
        log.debug('process_data',process_data);
        var work_order_Id = process_data.work_Order;
        log.debug("work_order_Id",work_order_Id);
        var work_Order_obj = record.load({
            type: record.Type.WORK_ORDER,
            id: work_order_Id,
            isDynamic: true
        }); 
       log.debug("work_Order_obj",work_Order_obj);
        var recId=work_Order_obj.save({
            enableSourcing: true,
            ignoreMandatoryFields: true
        });
       log.debug("recId",recId);
      

    }
    
   
Maira S Beginner Asked on February 16, 2023 in SuiteScript.
Add Comment
12 Answers

Hi,

Do you have a a summarize section to log any errors? If not, please add something like:

function summarize(summaryContext) {
    // Handle INPUT errors.
    let input_error_string = '';
    if (summaryContext.inputSummary.error) {
        input_error_string += `GET INPUT DATA ERRORS\n\n`;
        input_error_string += `[Details: ${summaryContext.inputSummary.error}]\n\n`;
    }

    // Handle MAP errors.
    let map_error_string = '';
    summaryContext.mapSummary.errors.iterator().each(function (key, err) {
        if (map_error_string.length === 0) {
            map_error_string = `MAP ERRORS\n\n`;
        }
        map_error_string += `[MAP    Error for Key: ${key} Details: ${err}]\n\n`;
        return true;
    });

    // Handle REDUCE errors.
    let reduce_error_string = '';
    summaryContext.reduceSummary.errors.iterator().each(function (key, err) {
        if (reduce_error_string.length === 0) {
            reduce_error_string = `REDUCE ERRORS\n\n`;
        }
        reduce_error_string += `[REDUCE Error for Key: ${key} Details: ${err}]\n\n`;
        return true;
    });

    if (input_error_string.length > 0 || map_error_string.length > 0 || reduce_error_string.length > 0) {
        log.error({
            title: 'ERROR',
            details: `${input_error_string}${map_error_string}${reduce_error_string}`
        });

        throw error.create({
            name: 'MAP_REDUCE_ERROR',
            message: `${input_error_string}${map_error_string}${reduce_error_string}`
        });
    }

    log.audit('INFO', 'END of script execution.');
};

Thanks,

Chris

Advanced Answered on February 16, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.