- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2021 12:25 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2021 01:02 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2021 02:06 AM
Thanks Mahesh for help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2021 01:02 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2021 01:55 AM
Thanks Ankur for wonderful help. It is working.