open a new record form when ui action is clicked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have two tables table 1 and table 2 both are extended from task. there is a ui action in table one which when clicked it should open a new form of table 2 and it should store the sysid of table 1 record in the parent field of table 2 record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Anshika Bhatna1 ,
To create a UI Action on Table 1 that opens a new form of Table 2 and sets the parent field on Table 2 to the sys_id of the current record on Table 1. for this you can Create a UI action on Table 1 that opens a new window/tab for Table 2 form using the URL pattern including sysparm_query=parent=<current_sys_id>. This pre-fills the parent reference in the new record. Use client-side script with window.open or server-side redirect depending on UX needs.
If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!
Kind Regards,
Shaik Mohammed Mustaq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Anshika Bhatna1 ,
Please follow below steps:
Create UI Action
Table: [Select Table 1]
Action name: create_child_table_2 (Best practice: use snake_case)
Active: Checked
Show Insert: Unchecked (Usually you only want to do this on an existing record)
Show Update: Checked
Client: Unchecked (We will use a server-side script)
Form button: Checked
Condition:!current.isNewRecord()
Script: Paste the following code into the script field. Make sure to replace u_table_2 with the actual name of your Table 2.
var targetTableName = 'u_table_2'; // REPLACE THIS with your Table 2 name
// Construct the URL for a new record (sys_id=-1)
var url = targetTableName + '.do?sys_id=-1';
// Append the query to pre-fill the 'parent' field with the current record's sys_id
url += '&sysparm_query=parent=' + current.sys_id;
// Optional: If you want to copy the Short Description as well, uncomment the line below:
// url += '^short_description=' + current.short_description;
// 4. Redirect the user to the new form
action.setRedirectURL(url);
Regards,
Vishal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it's an easy requirement
is your UI action client side or server side
share screenshots.
If Server Side then use this
// give your table name here
var url = 'yourTableName' + '.do?sys_id=-1&sysparm_query=parent=' + current.sys_id;
action.setRedirectURL(url);
if client side then use this
function openNewRecord() {
var url = 'yourTableName' + '.do?sys_id=-1&sysparm_query=parentField=' + g_form.getUniqueValue();
window.open(url, '-blank');
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader