If i want to write a map/reduce script to update r...
# ask-stanley-ai
u
If i want to write a map/reduce script to update revenue commitment reversals, what transaction type should I use in the script?
c
AI generated answer (using internal Slack threads):
To write a map/reduce script to update revenue commitment reversals, you should use the
revenuearrangement
transaction type in the script. This is because the revenue elements, which are the line level information on the arrangements, are the only way to update revenue elements. Here is a sample script that was provided 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
    };
});
****** 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.842101157
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833938181
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829993
Please provide your feedback on this answer.