Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

make a field mandatory when clicking on a ui action

Daiana Botta
Tera Contributor

Hi community, the client asked me for the following configuration: in the demand form, when clicking on the "approved" button he wants certain fields, for example due date (requeted_by) to ask it as mandatory and the flow not to continue. What is the best way? Ui_Policy combined with Client_scripts? Business rules? modify Ui_action? I read them! Thank you very much

5 REPLIES 5

KKM
Tera Guru

@Daiana Botta - In ServiceNow, you can enforce the "Due Date" field as mandatory before allowing the approval process to continue by using a Client Script or a Business Rule. The best approach, I would recommend is Business rules:

If you want to enforce this check at the database level (in case of API updates or by manual approvals), you can use the Business Rules.

Steps:

1. Go to System Definition → Business Rules.

2. Click New to create a Business Rule.

3. Fill in the details:

  • Name: Ensure Due Date before Approval
  • Table: demand (or your specific table)
  • Advanced: Checkbox (Check this option)
  • When to Run: Before Insert or Update
  • Condition: approval == "approved"

4. Script:

 
      if (current.approval == 'approved' && !current.due_date) { gs.addErrorMessage("Due Date is required before 
      approval."); current.setAbortAction(true); }

5. Click Submit to save.

How it Works?

  • If an approval action is triggered and due_date is empty, then update is blocked, and the user gets an error message.

Kindly mark it as correct/helpful, if it resolves your issue. Please press the "like" button to vote for me.

With Regards,

Krishna Kumar M