We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

UI Action Create Child Ticket Based Off of Parent Ticket

Rae Khan
Tera Contributor

Hi all, 

 

I am trying to create a child ticket UI action on the parent form. 

If you are on the parent form and click this button, it should ideally create and redirect you to the child ticket,

and fill the parent value on the child form with the Parent's original number. 

 

Here's the code I tried in the UI Action script:

 

function createChild() {
    var gr = new GlideRecord('child_form');
     gr.initialize();
    gr.u_parent = current.number;
    gr.insert();
 
    action.setRedirectURL("/child_form.do?sys_id="+gr.sys_id);
}
createChild();
 
Everything works except for the line:     gr.u_parent = current.number;
The parent field on the child field is left blank as opposed to being filled with the parent number. 
The 'u_parent' field is a reference field on the child form and the 'current.number' field is a string field.
 
Does anyone have any idea as to why this is not working?
Any help would be greatly appreciated. 
2 REPLIES 2

AniketC85155510
Kilo Patron

Hello @Rae Khan ,

 

You can try the below code once,

function createChild() {
var gr = new GlideRecord('child_form');
gr.initialize();

// Add a query to find the child record based on the parent number
gr.addQuery('u_parent.number', current.number);
gr.query();

if (gr.next()) {
// If a matching child record is found, set the reference field and update
gr.u_parent = current.sys_id; // assuming 'sys_id' is the correct reference field
gr.update();
} else {
// If no matching child record is found, insert a new record
gr.initialize();
gr.u_parent = current.sys_id;
gr.insert();
}

action.setRedirectURL("/child_form.do?sys_id=" + gr.sys_id);
}

createChild();

Please let me know your views on this and if you have any further query.


Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

Regards,
Aniket

Dr Atul G- LNG
Tera Patron

Hi @Rae Khan 

 

OOTB :

 

https://INSTANCENMAE.service-now.com/now/nav/ui/classic/params/target/sys_ui_action.do%3Fsys_id%3D117f90e367cb3200060071bfa2415a51%26sysparm_record_target%3Dsys_ui_action%26sysparm_record_row%3D5%26sysparm_record_rows%3D8%26sysparm_record_list%3DnameCONTAINSchild%255EORDERBYorder

 

LearnNGrowAtul_0-1702661586983.png

 

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************