how to setup valdation for form sumbit on suitelet
# ask-stanley-ai
s
how to setup valdation for form sumbit on suitelet
c
AI generated answer (using internal Slack threads):
To set up validation for form submit on a Suitelet, you can attach a Client Script to the
Form
instance. This can be done using
Form.clientScriptModulePath
or
Form.clientScriptFileId
. Here is an example of how you can add a button to your form:
Copy code
javascript
form.addSubmitButton({
    id: 'approvebuttonid',
    label: 'Approve'
});

form.addButton({
    id: 'rejectbuttonid',
    label: 'Reject'
});
In your Suitelet, you can then add logic to handle the actions of these buttons. For example:
Copy code
javascript
var isSelected = serverRequest.getSublistValue({
    group: 'custpage_sublistid',
    name: 'custpage_checkbox',
    line: i
});

if (isSelected === 'T') {
    var tranInternalID = serverRequest.getSublistValue({
        group: 'custpage_sublistid',
        name: 'custpage_internalid',
        line: i
    });

    var isRejectButtonClicked = serverRequest.getSublistValue({
        group:'custpage_sublistid',
        name: 'rejectbuttonid',
        line: i
    });
    isRejectButtonClicked = isRejectButtonClicked === 'T';

    if (isRejectButtonClicked) {
        record.submitFields({
            type: record.Type.SALES_ORDER,
            id: tranInternalID,
            values: {
                custbody_test: 'Rejected'
            }
        });
    } else {
        record.submitFields({
            type: record.Type.SALES_ORDER,
            id: tranInternalID,
            values: {
                custbody_approved: 'T'
            }
        });
    }
}
Please note that Suitelet forms are expected to only have one submit button. If you need to have more than one button that submits the form, you will need to write your logic with that in mind. If you are not using the NetSuite submit button on the Suitelet, you can just do a
<http://http.post|http.post>
. ****** 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.837618828
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.814719617
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.805934906
Please provide your feedback on this answer.