Using a client script, we toggle the isMandatory t...
# ask-stanley-ai
d
Using a client script, we toggle the isMandatory to true from false, however, I an still able to save the record without any value. Why is that?
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. ****** The
isMandatory
property in NetSuite's client script only adds a visual indicator (red asterisk) to the field, but it does not enforce the field validation upon saving the record. This is a known behavior in NetSuite and it's not a bug or an issue with your script. If you want to enforce the field validation, you will need to add a custom validation in the
saveRecord
function of your client script. Here's a simple example:
Copy code
javascript
function saveRecord(context) {
    var record = context.currentRecord;
    var isCardOnFile = record.getValue('custbody_mes_card_on_file');
    if (isCardOnFile && !record.getValue('custbody_mes_select_card_on_file')) {
        alert('Please select a card on file.');
        return false; // Prevent the record from being saved
    }
    return true; // Allow the record to be saved
}
In this example, if the 'custbody_mes_card_on_file' field is checked and the 'custbody_mes_select_card_on_file' field is empty, an alert will be displayed and the record will not be saved. This way, you can enforce the mandatory field validation on the client side.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859295547
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847157657
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845882416
Please provide your feedback on this answer.