what script can be used to prevent users from sele...
# ask-stanley-ai
n
what script can be used to prevent users from selecting an inactive account on transactions
c
AI generated answer (using internal Slack threads):
To prevent users from selecting an inactive account on transactions, you can use a SuiteScript. The script would need to be a User Event or Client Script that triggers on the field change event of the account field on the transaction record. The script would check if the selected account is inactive. If it is, the script would return an error message to the user and prevent the transaction from being saved. Here is a basic example of how this could be implemented:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/search'], function(record, search) {
    function beforeSubmit(context) {
        var newRecord = context.newRecord;
        var accountId = newRecord.getValue('account');
        var accountRecord = record.load({
            type: record.Type.ACCOUNT,
            id: accountId
        });
        var isInactive = accountRecord.getValue('isinactive');
        if (isInactive) {
            throw new Error('Cannot select an inactive account.');
        }
    }
    return {
        beforeSubmit: beforeSubmit
    };
});
Please note that this is a basic example and may need to be adjusted 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.834646404
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.807242334
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.805319786
Please provide your feedback on this answer.
m
is that ever possible by default?