Make the attachment and comments needs to mandatory.Error Message "Invalid value on Update"

armanoj
Mega Sage

Hi , 

in approval table make comments mandatory when they get approve , but get another error message along with custom error message  as "Invalid value on Update". Usinge BR I tried to make comments mandatory.

if (gs.nil(comments)) {

        current.setAbortAction(true);
        gs.addErrorMessage('Comments are mandatory when approving or rejecting.');
        return;
    }


is it possible remove that error message.
armanoj_0-1781758507212.png

 

 

4 REPLIES 4

Tanushree Maiti
Tera Patron

Hi @armanoj 

 

Try this:

Create/Update a Before Business Rule

  1. Navigate to System Definition > Business Rules.>Click New and fill in the fields:
    • Name: Make Comments Mandatory on Approval
    • Table: Approval [sysapproval_approver]
    • When: Before
    • Insert: Checked
    • Update: Checked

Condition tab, set:

    • State changes to Approved

 

(function executeRule(current, previous /*null when async*/) {

    if (gs.nil(current.comments)) {

        gs.addErrorMessage('Comments are mandatory when approving or rejecting.'');

        current.setAbortAction(true);

    }

})(current, previous);

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Yogesh11bhatt
Kilo Guru

Hi @armanoj ,

 

The custom error message is coming from your Business Rule, but the additional "Invalid value on Update" message is standard platform behavior. When the approval action tries to save the record and the update is aborted using current.setAbortAction(true);, ServiceNow automatically throws its generic database validation message alongside your custom message.

Here are two ways to handle this, depending on your needs:

Option 1: The Cleaner Approach (Recommended)

To completely eliminate the "Invalid value on Update" message, the platform best practice is to move this validation out of a Business Rule and into a Data Policy. A Data Policy enforces the rule securely at the server level but handles the UI error messaging gracefully.

  1. Navigate to System Policy > Rules > Data Policies.

  2. Create a new policy for the sysapproval_approver table.

  3. Condition: State is Approved OR State is Rejected.

  4. Add a Data Policy Rule for the Comments field and set Mandatory to True.

Option 2: Optimize Your Business Rule

If you have a strict requirement to keep this in a Business Rule, you must accept the double-message. However, you should update your script. Using gs.nil() directly on a journal field can be unreliable.

Update your script to check getJournalEntry(1) and ensure it only fires on the correct states:

JavaScript
 
// Check if the state is changing to approved/rejected and if the journal entry is empty
if ((current.state == 'approved' || current.state == 'rejected') && gs.nil(current.comments.getJournalEntry(1))) {
    gs.addErrorMessage('Comments are mandatory when approving or rejecting.');
    current.setAbortAction(true);
}

Additional things to check if you stick with the Business Rule:

  • Ensure this is a Before Update Business Rule.

  • Check if there are any conflicting Data Policies, Client Scripts, or UI Policies running on the same table.

Hope this helps!

 

Please mark this answer as Helpful if it resolves your question. 🙂

 

Thanks, Yogesh Bhatt

As per my reguirement approval table make the attachment and comments needs to mandatory.

Deepak Shaerma
Mega Sage

Hi @armanoj 

That secondary "Invalid value on Update" message is a classic ServiceNow annoyance.

It happens because of how current.setAbortAction(true) works. When your Business Rule forcefully aborts the database transaction, the platform's UI detects that the save failed unexpectedly. As a fallback, ServiceNow automatically throws that generic "Invalid value" or "Invalid Update" error to ensure the user knows the record didn't actually save, right alongside your custom message.


Note: You can use onSubmit Client script or Data Policy to make your comments mandatory before approval.

Happy to help! If this resolved your issue, kindly mark it as the correct answer   and Helpful and close the thread 🔒 so others can benefit too.

Warm Regards,

Deepak Sharma

Community Rising Star 2025