UI Action Create Child Ticket Based Off of Parent Ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 07:39 AM - edited 12-15-2023 07:40 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 07:47 AM - edited 12-15-2023 07:50 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:33 AM
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
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
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/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************