UI action Client & Server Side

SnowDevOps
Giga Guru

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

SnowDevOps_0-1726384099757.png

 

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

 

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello @SnowDevOps  plz use  the below code its working.

akshaypithore_0-1726402700159.pngakshaypithore_1-1726402730684.png

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.close_code ='test';
            gr.close_notes ='test1;'
        gr.update();
    }
    action.setRedirectURL(current);
}
akshaypithore_3-1726402828643.png

 

akshaypithore_2-1726402790893.png

 

akshaypithore_4-1726402860858.png

Please let me know if this solution works for you, and mark my answer as correct and helpful if it does."

View solution in original post

5 REPLIES 5

Gangadhar Ravi
Giga Sage
Giga Sage

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.

Brad Bowman
Kilo Patron
Kilo Patron

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

 

 

Mani A
Tera Guru

 

 

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

 

 

@SnowDevOps accept my solution and click helpful if it resolve your issue