Copying records and inheriting views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2025 06:29 PM
I am copying records using the following script.
However, the new record form that appears after copying is the default view.
Is it possible to copy a record while maintaining the view?
I would like it to have the same functionality as copying an incident record.
<Requirements>
- Display a new record form with the specified fields copied
- Display the new record form with the view before copying
var new_rec = new GlideRecord("incident");
new_rec.initialize();
new_rec.setValue("u_field1", current.getValue("u_field1"));
new_rec.setValue("u_field2", current.getValue("u_field2"));
action.openGlideRecord(new_rec);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2025 08:11 PM
view is just to display the form fields and copying/inserting is a database backend logic
Both are different things.
but you can try to do something but I haven't tested this
// Server-side UI Action script
// Get the current view
var view = gs.action.getGlideURI().get('sysparm_view') || 'default';
// Build the redirect URL with field values and view
var url = '/incident.do?sys_id=-1' +
'&u_field1=' + encodeURIComponent(current.u_field1) +
'&u_field2=' + encodeURIComponent(current.u_field2) +
'&sysparm_view=' + encodeURIComponent(view);
// Redirect to the new record form with the same view and pre-filled fields
action.setRedirectURL(url);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2025 08:21 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2025 10:13 PM
// Server-side UI Action script
// Get the current view
var view = gs.action.getGlideURI().get('sysparm_view') || 'default';
// Build the redirect URL with field values and view
var url = '/incident.do?sys_id=-1' +
'&short_description=' + encodeURIComponent(current.short_description) +
'&caller_id=' + encodeURIComponent(current.caller_id) +
'&sysparm_view=' + encodeURIComponent(view);
// Redirect to the new record form with the same view and pre-filled fields
action.setRedirectURL(url);
Thank you for your reply.
But unfortunately this didn't work.