how do i prevent mileage rate from being changed o...
# ask-stanley-ai
t
how do i prevent mileage rate from being changed on expense report
c
AI generated answer (using internal Slack threads):
To prevent the mileage rate from being changed on an expense report, you can consider implementing a SuiteScript that locks the field once the expense report is created. This way, the mileage rate cannot be edited after the initial entry. Here is a sample SuiteScript code that you can use as a starting point:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/runtime'], function(record, runtime) {
    function beforeSubmit(context) {
        if (context.type !== context.UserEventType.CREATE) {
            var newRecord = context.newRecord;
            var oldRecord = context.oldRecord;
            var newMileageRate = newRecord.getValue('custrecord_mileage_rate');
            var oldMileageRate = oldRecord.getValue('custrecord_mileage_rate');
            if (newMileageRate !== oldMileageRate) {
                throw 'Mileage rate cannot be changed after creation.';
            }
        }
    }
    return {
        beforeSubmit: beforeSubmit
    };
});
This script will throw an error if a user tries to change the mileage rate after the expense report has been created. Please replace 'custrecord_mileage_rate' with the actual field id of the mileage rate on your expense report record. ****** 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.835144162
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.795043945
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.790405393
Please provide your feedback on this answer.