Unable to attach child request to Parent request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:23 PM
Hi Team,
I want to create child request for my form and attach to my parent form by displaying that child request in one of the tabs in parent form. I was able to create request with UI action but unable to attach the child request to parent.
Can anyone please help me.
Best Regards,
Shravan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:27 PM
Can you share your code?
And are you sure that your requirement has the need of requests being in a parent/child order? A request has requested items and requested items have tasks. Wouldn't it be better to have multiple requested items under one request?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:30 PM
Hi @shravankath
Is the below Prerequisites are correct...If yes then only we will be able to create or guide you with the code??
- You have created a UI action to create a new child request.
- You have a parent form (e.g., Incident, Request, etc.) and a child form (e.g., Child Request, Sub-Request, etc.).
please share your code snippet
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:37 PM
Yes, I created UI action to create request with below code. Whether it is requested item or child request,
I would like to know what is the best way to do this parent child relationship in requests in servicenow.
var url = new GlideURL("u_child.do");
url.set("sys_id" , "-1");
url.set("sysparm_query" , "^parent=" + current.sys_id);
action.setRedirectURL(url.toString()+"");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:41 PM
Thanks for your Reply follow the below procedure :-
Note :- Below info is already available on ServiceNow Community :-
Step 1: Create a relationship between the parent and child tables
- Go to System Definition > Tables and find the parent table (e.g., Incident).
- Click on the parent table and navigate to the Related Lists tab.
- Click New to create a new related list.
- Fill in the details:
- Name: Give a name to the related list (e.g., "Child Requests").
- Table: Select the child table (e.g., Child Request).
- Type: Select "Parent-Child" as the relationship type.
- Parent field: Select the field on the parent table that will be used to link to the child table (e.g., "Number" or "Sys ID").
- Child field: Select the field on the child table that will be used to link to the parent table (e.g., "Parent" or "Parent ID").
- Click Submit to save the related list.
Step 2: Configure the UI action to create a child request
- Go to System UI > UI Actions and find the UI action you created to create a new child request.
- Click on the UI action and navigate to the Action tab.
- In the Action script, add the following code to set the parent field on the child request:
var childRequest = new GlideRecord('child_request_table_name');
childRequest.parent = current.sys_id; // Set the parent field on the child request
childRequest.insert();
Replace
child_request_table_name
with the actual table name of your child request table.Step 3: Display the child requests in a tab on the parent form
- Go to System UI > Forms and find the parent form.
- Click on the parent form and navigate to the Tabs tab.
- Click New to create a new tab.
- Fill in the details:
- Tab label: Give a label to the tab (e.g., "Child Requests").
- Related list: Select the related list you created in Step 1 (e.g., "Child Requests").
- Click Submit to save the tab.
Now, when you create a new child request using the UI action, it should be attached to the parent form and displayed in the tab you created.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/