Write me a map/reduce script that searches all rec...
# ask-stanley-ai
j
Write me a map/reduce script that searches all records with an account type of Accounts Payable that were created or edited within the last 30 minutes. For each customer associated with those accounts payable impacts, if the overduebalance > 0 set the custentity_paymentstatus field to 2 otherwise set it to 1.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like a Map/Reduce script would be the most suitable solution for your requirement. Here is a high-level overview of how you could structure your script: 1. getInputData stage: In this stage, you would create a search that looks for all records with an account type of Accounts Payable that were created or edited within the last 30 minutes. You would return this search so that the Map/Reduce script can handle the execution. 2. map stage: For each record returned by the search, you would retrieve the associated customer and check the overdue balance. If the overdue balance is greater than 0, you would set the
custentity_paymentstatus
field to 2. Otherwise, you would set it to 1. Here is a pseudo-code example of how this might look:
Copy code
javascript
function getInputData() {
    var search = search.create({
        type: 'transaction',
        filters: [
            ['type', 'anyof', 'VendBill', 'VendCred', 'VendPymt'],
            'AND',
            ['accounttype', 'anyof', 'AccountsPayable'],
            'AND',
            ['lastmodifieddate', 'within', 'last30minutes']
        ]
    });
    return search;
}

function map(context) {
    var searchResult = JSON.parse(context.value);
    var customerId = searchResult.values['customer.internalid'];
    var overdueBalance = searchResult.values['customer.overduebalance'];

    var customerRecord = record.load({
        type: 'customer',
        id: customerId
    });

    if (overdueBalance > 0) {
        customerRecord.setValue('custentity_paymentstatus', 2);
    } else {
        customerRecord.setValue('custentity_paymentstatus', 1);
    }

    customerRecord.save();
}
Please note that this is a simplified example and may not cover all edge cases. You would need to adjust it to fit your specific needs. ****** 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.840698838
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835532367
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.832845807
Please provide your feedback on this answer.