Adding error message and stop form submission.

Anand Joshi
Kilo Contributor

Hello Everyone,

 

I have a task where I need to show error message WHEN user tries to update an incident's state to resolved and there is an incident task whose state is open. Can someone guide me for this. 

 

Regards,

Anand.

1 ACCEPTED SOLUTION

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Anand,

You need to create a Before Update BR for this on incident table.

Action: State To Resolved or Closed

Script:

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

var gr = new GlideRecord('incident_task);
gr.addQuery('active','true');
gr.addQuery('state',1); // you may want to use this if you need to check other states like Pending etc. (('state', 'NOT IN', '3,4,7');)
gr.addQuery('incident',current.sys_id);
gr.query();
if (gr.next()) {
gs.addErrorMessage('Please close the incident task(s) before resolving the incident');
current.setAbortAction(true);
}

})(current, previous);

 

Please mark correct/helpful if applicable.

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

View solution in original post

1 REPLY 1

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Anand,

You need to create a Before Update BR for this on incident table.

Action: State To Resolved or Closed

Script:

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

var gr = new GlideRecord('incident_task);
gr.addQuery('active','true');
gr.addQuery('state',1); // you may want to use this if you need to check other states like Pending etc. (('state', 'NOT IN', '3,4,7');)
gr.addQuery('incident',current.sys_id);
gr.query();
if (gr.next()) {
gs.addErrorMessage('Please close the incident task(s) before resolving the incident');
current.setAbortAction(true);
}

})(current, previous);

 

Please mark correct/helpful if applicable.

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.