Map Reduce script to set the value in one field to another field.

Setting the value in one field to another field in the same record.

const getInputData = (inputContext) => {

            return search.create({

                type: “customrecord_vr_svcord”,

                filters: [

                    [“custrecord_vr_svcord_turnaround”, “anyof”, “6”, “1”, “2”, “3”, “4”, “5”, “7”, “8”, “9”],

                    “AND”,

                    [“custrecord_jj_st_turn_around_time”, “isempty”, “”],

                    “AND”,

                    [“internalid”, “anyof”, “2279”, “2281”, “2282”]

                ],

                columns: [

                    search.createColumn({ name: “custrecord_vr_svcord_turnaround”, label: “Turnaround Time” }),

                    search.createColumn({ name: “custrecord_jj_st_turn_around_time”, label: “Turnaround Time Text” })

                ]

            });

        }

 const reduce = (reduceContext) => {

            const result = JSON.parse(reduceContext.values[0]);

            const recordId = result.id;

            const turnAroundTimeValue = result.values.custrecord_vr_svcord_turnaround;

            // Extract the text value

            const turnAroundTimeText = turnAroundTimeValue.text;

            try {

                // Update the Turnaround Time Text field with the Turnaround Time value

                record.submitFields({

                    type: ‘customrecord_vr_svcord’,

                    id: recordId,

                    values: {

                        custrecord_jj_st_turn_around_time: turnAroundTimeText

                    },

                    options: {

                        ignoreMandatoryFields: true

                    }

                });

                log.debug(`Updated Record ID: ${recordId}`, `Set Turnaround Time Text to: ${turnAroundTimeText}`);

            } catch (e) {

                log.error(`Error updating Record ID: ${recordId}`, e.message);

            }

        }

const summarize = (summaryContext) => {

            summaryContext.reduceSummary.errors.iterator().each((key, error) => {

                log.error(`Error for Record ID: ${key}`, error);

                return true;

            });

            log.debug(“Process Completed”, `Total Records Processed: ${summaryContext.reduceSummary.keys.length}`);

        }

        return { getInputData, reduce, summarize }

    });

Leave a comment

Your email address will not be published. Required fields are marked *