The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Minimum character requirement in Additional Comments and Close Notes upon resolve

apassey
Kilo Explorer

Would someone be able to help point me in the right direction on how to make "Additional Comments" and "Close Notes" have a minimum character requirement upon an Incident being set to the "Resolved" state?  

 

Basically what we are trying to do is ensure that the client communication that is sent out when an incident is resolved actually contains a communication to the client rather than something like a period or ellipses and if they try to input less than the minimum, we would like an error message to come up to say something like "Please enter a minimum of 18 characters". We would like the close notes to contain valid information as well.

 

Thank you!

April

9 REPLIES 9

Ravi Gaurav
Giga Sage
Giga Sage

Hi @apassey 

  • Set the Table to Incident and the Type to onChange
  • Set the Field to State

And use the below code ...

 

if (newValue == 'Resolved') {
    var additionalComments = g_form.getValue('additional_comments');
    var closeNotes = g_form.getValue('close_notes');
   
    if (additionalComments.length < 18 || closeNotes.length < 18) {
      g_form.addErrorMessage('Please enter a minimum of 18 characters for Additional Comments and Close Notes');
      g_form.setMandatory('additional_comments', true);
      g_form.setMandatory('close_notes', true);
    }
  }
--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

rc26
Tera Contributor

Thanks for the reply!!

But, Currently we don't have any state condition. Whenever user enters work notes or additional comments, need to validate the length should be greater than 25 chars.

1. I wrote BR on before insert/update, it is restricting the work notes but not displaying any error message on form.

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

    if (current.work_notes.changes() && current.work_notes.toString().length < 25) {
        gs.addInfoMessage("test");
        current.setAbortAction(true);
        gs.addErrorMessage("Worknotes needs to have 25 characters");
    }

    if (current.comments.changes() && current.comments.toString().length < 25) {
        gs.addErrorMessage("Additional comments needs to have 25 characters");
        current.setAbortAction(true);
    }

})(current, previous);
2. Wrote on change client script on change of worknotes, it is not working as expected it is popping alert for each character entered in worknotes.

Hi @rc26 
It is displaying Error message on the Business Rule Form. So the conclusion is we are not updating the entire form , we are clicking on "POST" button which doesn't allow this on the Form.

Its a know issue.

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

rc26
Tera Contributor

Thanks for the response!!

Is there other way to validate work notes length on incident form?

Do mark as Helpful and accept if you find it insightfull...

One Alternative is use onSubmit Client script Validation. But you have to convey this to user ..
and one more use a custom field to store the Information and once user click on POST then load the page with messgae

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/