How to Display error message on Request Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:19 AM
Hi Team,
How to display an error message on the Request Item table, when a user closes the request item without completing the catalog task (Sc task).
I have tired the before update business rule with below code:
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.sys_id);
gr.query();
while (gr.next()) {
if (gr.active == true) {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
current.state=8;
current.setAbortAction(true);
It's working fine, but the error message is displayed on both the requested item and catalog task also.
Regards,
Mahesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:22 AM - edited 08-07-2023 06:23 AM
the message will be shown on whatever the current screen user is on
Your script can be improved , Try this
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.sys_id);
gr.addQuery('active', true);
gr.query();
if(gr.next()) {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
//current.state=8; you dont need this as you are aborting the action
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:41 AM - edited 08-07-2023 06:42 AM
Hi Mahesh,
Please tweak the script with below script and let me know if it works for you or not!
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.sys_id);
gr.query();
while (gr.next()) {
var state = gr.getValue('state');
if (state!= 3 || state !=4) //Change this value to Close Complete value in your instance {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
}
current.setAbortAction(true);
}
Also make sure that your Business rule is running on RITM table & Before update with Filter condition as State Changes to Closed Complete.
If you find my answer Helpful please mark it Helpful or Correct!
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 06:45 AM
you can use before update BR on sc_task
Condition: State [IS ONE OF] [Closed Complete/Closed Incomplete/Closed Skipped]
Script:
1) you can use addActiveQuery()
2) you can use setLimit(1) since you want to check if any 1 sc_task is active for that RITM
3) you can use hasNext() instead of next() since you just want to check if record exists or not
var gr = new GlideRecord("sc_task");
gr.addActiveQuery();
gr.addQuery("request_item", current.sys_id);
gr.setLimit(1);
gr.query();
if(gr.hasNext()) {
gs.addErrorMessage("Your error message here");
current.setAbortAction(true);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 04:05 AM
Hi Ankur,
I have tried the above code, the error message is displayed on the catalog task also when I am trying to close the task.
Regards,
Mahesh