map reduce script to update lines on Rev Commit. M...
# ask-stanley-ai
u
map reduce script to update lines on Rev Commit. Make it flexible so I can use it for any transaction line and dependent on saved search.
c
AI generated answer (using internal Slack threads):
Based on the conversations, you can create a Map/Reduce script to update lines on Revenue Commitment (Rev Commit) or any other transaction line. The script will be flexible and can be used for any transaction line, depending on the saved search. Here is a sample script that was shared in the conversations:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType MapReduceScript
 */
define(['N/record', 'N/search'], function(record, search) {

    function getInputData() {
        return search.create({
            type: "revenuearrangement",
            filters: [
                ["type", "anyof", "RevArrng"], 
                "AND", 
                ["internalid","anyof","91518","91519"]
            ],
            columns: [
                search.createColumn({name: "internalid", label: "Internal ID"})
            ]
        });
    }

    function map(context) {
        var searchResult = JSON.parse(context.value);
        var recordId = searchResult.id;
        context.write({
            key: recordId,
            value: recordId
        });
    }

    function reduce(context) {
        context.values.forEach(function(recordId) {
            try {
                var recordToEdit = record.load({
                    type: 'revenuearrangement', 
                    id: recordId
                });

                var lineCount = recordToEdit.getLineCount({
                    sublistId: 'revenueelement'
                });

                for (var i = 0; i < lineCount; i++) {
                    recordToEdit.setSublistValue({
                        sublistId: 'revenueelement',
                        fieldId: 'createrevenueplanson',
                        line: i,
                        value: '-1' 
                    });
                }

                recordToEdit.save();
            } catch (e) {
                log.error("Error", {
                    "ID": recordId,
                    "Error": e.message
                });
            }
        });
    }

    return {
        getInputData: getInputData,
        map: map,
        reduce: reduce
    };
});
This script uses the Map/Reduce script type in SuiteScript 2.0. It first creates a search in the
getInputData
function to get the records you want to update. Then, in the
map
function, it writes each record's internal ID to the context. In the
reduce
function, it loads each record, updates the line items, and saves the record. You can modify the search in the
getInputData
function to target the specific transaction lines you want to update. You can also modify the
reduce
function to update the specific fields you want on the line items. ****** 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.837070227
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828071117
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826265216
Please provide your feedback on this answer.