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.

How to create an error message using client script

Raphael Dizon
Mega Expert

Hello,

I have a task wherein I have to create an error message using client script. The scenario is whenever a user changes the state of the incident to resolve and an incident task or job order is still open, it will display an error message which says "Please Close all incident tasks" or "Please Close all Job orders" after submitting the incident. Thank you.

Regards,

Raphael

1 ACCEPTED SOLUTION

Service_RNow
Mega Sage

HI,

Please write a Business rule on the INcident table 

When to run ->Before,Update

Action-> state To close

Advance code:

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

// Add your code here
var gr = new GlideRecord('incident_task);

gr.addQuery('active','true');

gr.addQuery('incident',current.sys_id);

gr.query();

if (gr.next()) {

gs.addErrorMessage('Incident cannot be closed before the incident task closure');

current.setAbortAction(true);

}

})(current, previous);

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

View solution in original post

12 REPLIES 12

Manoj Verma1
Giga Contributor

hi

You can use alert() message or g_form.addErrorMessage(message). When do you want this error message to be displayed? When user submits the form?

Hi,

Yes I want this error to show whenever a user changes the incident to resolve and updates it and it will only show when an incident task is still open

Service_RNow
Mega Sage

HI,

Please write a Business rule on the INcident table 

When to run ->Before,Update

Action-> state To close

Advance code:

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

// Add your code here
var gr = new GlideRecord('incident_task);

gr.addQuery('active','true');

gr.addQuery('incident',current.sys_id);

gr.query();

if (gr.next()) {

gs.addErrorMessage('Incident cannot be closed before the incident task closure');

current.setAbortAction(true);

}

})(current, previous);

 

Please mark reply as Helpful/Correct, if applicable. Thanks!