- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 01:39 PM
Hello Everyone,
I hope you all are doing good. 🙂
I need to add an alert(pop-up message) as "Please close all Ptasks before taking this action" to the UI action when all tasks are not closed in the Problem ticket. And If task is closed then state field will update.
When we will click UI Action "RCA Completed", if task is closed then state will update to "RCA Completed" and if task is not closed then it will pop up a message.
I wrote an UI action but after closing the task also ,state is not updating. 😞
In the Problem ticket,
UI action: RCA Completed
Phase: Investigation & Analysis
Stage: Investigation & Analysis
State: Work in Progress
Please refer below, I tried to write script in UI Action, but after closing the task also ,state is not updating. 😞
var gr = new GlideRecord("problem_task");
gr.addQuery("state", '1'); // value 1 is for Open
gr.addQuery("active", 'true');
gr.addActiveQuery();
gr.query();
if (gr.getRowCount() > 0) {
alert("test"); alert is not working in server script( like UI Action)
//gs.log("2"); not working as well
gs.addInfoMessage("Please close all Ptasks before taking this action"); its working but the message is popping up in the list rather than in the form.
}
else
{ current.state = 105; Not updating
//current.u_stage = 103;
current.approval = "requested"; Not updating
current.update();
}
Any ideas on how this might be able to function?
Thanks in advance!
Swati
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 02:13 PM
Since you do not want the record to save, you should return after your info message.
var gr = new GlideRecord("problem_task");
gr.addQuery("state", '1'); // value 1 is for Open
gr.addQuery("active", 'true');
gr.addActiveQuery();
gr.query();
if (gr.getRowCount() > 0) {
// alert("test"); alert is not working in server script( like UI Action)
// gs.log("2"); not working as well
gs.addInfoMessage("Please close all Ptasks before taking this action");
return;
} else {
current.state = 105;
//current.u_stage = 103;
current.approval = "requested";
current.update();
action.setRedirectURL(current); //Added this in to stay on the page.
}
I also added a setRedirectURL method to stay on the same page after the button is pressed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 02:13 PM
Since you do not want the record to save, you should return after your info message.
var gr = new GlideRecord("problem_task");
gr.addQuery("state", '1'); // value 1 is for Open
gr.addQuery("active", 'true');
gr.addActiveQuery();
gr.query();
if (gr.getRowCount() > 0) {
// alert("test"); alert is not working in server script( like UI Action)
// gs.log("2"); not working as well
gs.addInfoMessage("Please close all Ptasks before taking this action");
return;
} else {
current.state = 105;
//current.u_stage = 103;
current.approval = "requested";
current.update();
action.setRedirectURL(current); //Added this in to stay on the page.
}
I also added a setRedirectURL method to stay on the same page after the button is pressed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 02:15 PM