Write me a map/reduce script in suitescript 2.1 th...
# ask-stanley-ai
j
Write me a map/reduce script in suitescript 2.1 that searches all transactions records with an account type of Accounts Payable. For each the linked customer associated with those transactions set the custentity_paymentstatus value to 1.
c
AI generated answer (using internal Slack threads):
Based on the conversations, here is a sample of a Map/Reduce script in SuiteScript 2.1 that searches all transactions records with an account type of Accounts Payable. For each linked customer associated with those transactions, it sets the
custentity_paymentstatus
value to 1.
Copy code
javascript
/**
 * @NApiVersion 2.1
 * @NScriptType MapReduceScript
 */
define(['N/search', 'N/record'], function(search, record) {
    function getInputData() {
        return search.create({
            type: 'transaction',
            filters: [
                ['accounttype', 'anyof', 'AccountsPayable']
            ],
            columns: ['internalid']
        });
    }

    function map(context) {
        var searchResult = JSON.parse(context.value);
        var transactionId = searchResult.id;

        var transactionRecord = record.load({
            type: 'transaction',
            id: transactionId
        });

        var customerId = transactionRecord.getValue('entity');

        if (customerId) {
            record.submitFields({
                type: 'customer',
                id: customerId,
                values: {
                    custentity_paymentstatus: 1
                }
            });
        }
    }

    return {
        getInputData: getInputData,
        map: map
    };
});
This script first creates a search that retrieves all transactions with an account type of Accounts Payable. In the map stage, it loads each transaction record, retrieves the linked customer, and sets the
custentity_paymentstatus
field to 1. ****** 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.845565081
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837756455
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833273828
Please provide your feedback on this answer.