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

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!

Sri Harsha3
Tera Expert

You need to do that on submit of client script.

Hi,

how can you check if there are still any open incident tasks in an incident without using GlideRecord as it is not allowed I think in a client script. Thanks

Regards, 

Raphael

I didn't say without using GlideRecord you can handle it on submit and write the logic accordingly.

On submit make a GlideAjax request to check the task is closed or not and return the value. Based on the response show the error message.