I have a custom date field on a customer record - ...
# ask-stanley-ai
s
I have a custom date field on a customer record - when today's date is the same as the date in the date field, I want to change the price level of that customer. What is the best way to accomplish this?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** To accomplish your task, you can use a Scheduled SuiteScript. This script will run daily and check if the current date matches the date in the custom date field on the customer record. If it does, the script will update the price level of that customer. Here is a basic example of how you could structure this script:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType ScheduledScript
 */
define(['N/record', 'N/search'], function(record, search) {
    function execute(context) {
        var today = new Date();
        today.setHours(0,0,0,0); // to remove time from date

        var customerSearch = search.create({
            type: search.Type.CUSTOMER,
            filters: [['custentity_your_custom_date_field', 'on', today]]
        });

        customerSearch.run().each(function(result) {
            var customerId = result.id;

            try {
                record.submitFields({
                    type: record.Type.CUSTOMER,
                    id: customerId,
                    values: {
                        pricelevel: 'internalid_of_new_price_level'
                    }
                });
                log.debug('Customer Updated', customerId);
            } catch (e) {
                log.error('Error Updating Customer', e);
            }

            return true; // to continue the search
        });
    }

    return {
        execute: execute
    };
});
Please replace
'custentity_your_custom_date_field'
with the script id of your custom date field and
'internalid_of_new_price_level'
with the internal id of the new price level. Remember to deploy this script as a Scheduled Script in NetSuite and schedule it to run daily. Please note that this is a basic example and might need to be adjusted to fit your specific needs. Always test scripts in a sandbox environment before deploying them in a live environment.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829473734
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828138351
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827588141
Please provide your feedback on this answer.