We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to generate an error message when the field value changes?

shiz
Tera Contributor

I have a Screen

When I changed the ‘Week Starts On' of value is not this Week of Manday date ,Then system generate an error message!

shiz_0-1731385769122.png

How to write a Business Rule?

shiz_1-1731385956618.pngshiz_2-1731385971022.png

 

1 ACCEPTED SOLUTION

@shiz 

 

Try with below script :

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

    var weekStartOn = new GlideDateTime(current.u_week_starts_on); // Please replace u_week_starts_on with your column Name
    var day = weekStartOn.getDayOfWeekLocalTime();
    if (day != '1') {
        gs.addErrorMessage('Today is not Monday'); // Change the message as per your requirement
    }


})(current, previous);
Thanks and Regards
Amit Verma

View solution in original post

3 REPLIES 3

vermaamit16
Kilo Patron

shiz
Tera Contributor

@vermaamit16  hello

I'm not very familiar with the syntax of this writing. How should I write it specifically? Thank you very much.

@shiz 

 

Try with below script :

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

    var weekStartOn = new GlideDateTime(current.u_week_starts_on); // Please replace u_week_starts_on with your column Name
    var day = weekStartOn.getDayOfWeekLocalTime();
    if (day != '1') {
        gs.addErrorMessage('Today is not Monday'); // Change the message as per your requirement
    }


})(current, previous);
Thanks and Regards
Amit Verma