How to Display error message on Request Item

maheshch18
Tera Contributor

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

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

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);
}

 

 

 

 

-Anurag

Utpal Dutta
Tera Guru

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

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@maheshch18 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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