- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 12:13 AM
Hello Team
I'm trying to write a UI action button for this scenario.
The button will be displayed in the incident form, when the user clicks on that button then a confirmation pop-up should be shown to the User whether he wants to close the attached child incident or not?.. If he said Yes then the child incident will be closed. I created the UI action button and wrote the code. Then I went to test it and the button didn't do anything when I clicked. I think the code is right. Or if you have another way to write this. Please suggest! Thank You for your help
function demoClientScript() {
var answer = confirm("Are you sure to close the attached Child Incident");
if (answer == true)
{
gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
}
}
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.query();
while (gr.next()) {
gr.state = '7';
gr.update();
}
action.setRedirectURL(current);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 05:22 AM
Hello @SnowDevOps plz use the below code its working.
Please let me know if this solution works for you, and mark my answer as correct and helpful if it does."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 03:49 AM
Hi @SnowDevOps Please try below
function resolveIncident() {
var answer = confirm("Are you sure to close the attached Child Incident");
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
}
}
if (typeof window == 'undefined')
serverResolve();
// Server-side function
function serverResolve() {
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.query();
while (gr.next()) {
gr.state = '7';
gr.update();
}
action.setRedirectURL(current);
}
Please mark my answer correct and helpful if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 04:10 AM - edited 09-15-2024 04:12 AM
Not shown - do you have the Onclick field populated with demoClientScript() ? Also, you need to wrap your code outside of the function in an if statement, since it's using server syntax, and you should return false if the confirm is cancelled:
function demoClientScript() {
var answer = confirm("Are you sure to close the attached Child Incident");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
} else {
return false;
}
}
if (typeof window == 'undefined') {
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.query();
while (gr.next()) {
gr.state = '7';
gr.update();
}
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 04:29 AM - edited 09-15-2024 04:30 AM
function demoClientScript() {
var answer = confirm("Are you sure to close the attached Child Incident");
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
}
}
if (typeof window == 'undefined')
{
closeChild();
}
function closeChild() {
var childIncident = new GlideRecord('incident');
childIncident.addQuery('parent_incident', current.sys_id);
childIncident.query();
while (childIncident.next()) {
childIncident.state = '7';
childIncident.update();
}
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 10:06 PM
@SnowDevOps accept my solution and click helpful if it resolve your issue