Write a suitescript 2.1 map/reduce script to searc...
# ask-stanley-ai
j
Write a suitescript 2.1 map/reduce script to search for transactions with a lastmodifieddate of today and for each transaction, get the customer internal id and set the custentity_paymentstatus field on the customer record to 1.
c
AI generated answer (using internal Slack threads):
Based on the conversations, here is a sample SuiteScript 2.1 map/reduce script that can be used to search for transactions with a lastmodifieddate of today and for each transaction, get the customer internal id and set the custentity_paymentstatus field on the customer record 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: [
                ['lastmodifieddate', 'on', 'today']
            ],
            columns: ['internalid', 'entity']
        });
    }

    function map(context) {
        var searchResult = JSON.parse(context.value);
        var customerId = searchResult.values['entity'][0].value;
        context.write(customerId, null);
    }

    function reduce(context) {
        var customerId = context.key;
        record.submitFields({
            type: record.Type.CUSTOMER,
            id: customerId,
            values: {
                custentity_paymentstatus: 1
            }
        });
    }

    return {
        getInputData: getInputData,
        map: map,
        reduce: reduce
    };
});
This script creates a search in the
getInputData
stage to find all transactions with a lastmodifieddate of today. The
map
stage then processes each search result, extracting the internal id of the customer associated with each transaction. The
reduce
stage then updates the
custentity_paymentstatus
field on each customer record 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.83227545
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83203131
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.82824713
Please provide your feedback on this answer.