UI Action script to close child incident.

Tara16
Giga Contributor

Hi All,

I wrote code in UI actions to close child incidents but it is not working. Can someone correct this code. It is given below.

function demoChildClose()
{
var answer=confirm("Do you really want to close 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.setValue('state', 7);
gr.update();
}
action.setRedirectURL(current);
}

 

 

 

 

Thanks

1 ACCEPTED SOLUTION

Hi,

Points to check

1) 1st of all is the confirm box coming

2) is the action name sys_demoaction correct?

3) did the control go to the server side?

4) are you storing the parent in parent or parent_incident fields?

Can you try this updated script

I have made changes to script shared by Mahesh

1) removed extra curly bracket

2) add or condition in script

function demoChildClose()
{
    var answer=confirm("Do you really want to close child incident?");
    if(answer==true)
    {
        gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
    }
} // you should close the client side code here

if(typeof window == 'undefined')
    runServerCode();

function runServerCode(){
    var gr =new GlideRecord('incident');
    gr.addQuery('parent_incident', current.getUniqueValue()).addOrCondition('paent', current.getUniqueValue());
    gr.query();
    while(gr.next())
    {
        gr.setValue('state', 7);

        gr.setValue('close_code','Solved (Permanently)');

        gr.setValue('close_notes', 'Closed from script');

        gr.update();
    }
    action.setRedirectURL(current);
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Thanks Mahesh for help.

Hi,

Points to check

1) 1st of all is the confirm box coming

2) is the action name sys_demoaction correct?

3) did the control go to the server side?

4) are you storing the parent in parent or parent_incident fields?

Can you try this updated script

I have made changes to script shared by Mahesh

1) removed extra curly bracket

2) add or condition in script

function demoChildClose()
{
    var answer=confirm("Do you really want to close child incident?");
    if(answer==true)
    {
        gsftSubmit(null, g_form.getFormElement(), 'sys_demoaction');
    }
} // you should close the client side code here

if(typeof window == 'undefined')
    runServerCode();

function runServerCode(){
    var gr =new GlideRecord('incident');
    gr.addQuery('parent_incident', current.getUniqueValue()).addOrCondition('paent', current.getUniqueValue());
    gr.query();
    while(gr.next())
    {
        gr.setValue('state', 7);

        gr.setValue('close_code','Solved (Permanently)');

        gr.setValue('close_notes', 'Closed from script');

        gr.update();
    }
    action.setRedirectURL(current);
}

Regards
Ankur

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

Thanks Ankur for wonderful help. It is working.