Copy change to show the new change record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 12:14 AM
Hi,
Is there a way to restrict the OOTB Copy change option to stay on the new change record upon Save.
The OOTB behavior redirects to the change record being copied upon click on Copy Change > Save
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 12:45 AM - edited 04-24-2023 12:46 AM
Hi,
Here are the steps to achieve this:
- Create a new UI Script. Navigate to "System Definition" > "UI Scripts" and click on "New". Enter a name and a short description for the script, select the "Global" checkbox, and paste the following code into the "Script" field:
function onLoad() {
if (window.location.pathname.indexOf('/change.do') === -1) {
return; // Not on change form
}
var params = new URLSearchParams(window.location.search);
var copyParam = params.get('sysparm_copy');
if (!copyParam) {
return; // Not copying a change
}
var saveButton = document.querySelector('button#sysverb_insert');
if (saveButton) {
saveButton.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default form submission
var form = saveButton.form;
var action = form.action;
var sysId = action.match(/id=([^&]+)/)[1];
var newUrl = '/change.do?id=' + sysId; // Redirect to the new change record
window.location.href = newUrl;
});
}
}
2. Save the UI Script. Click on "Submit" to save the UI Script.
3. Test the modified behavior. Navigate to a change record in ServiceNow and click on the "Copy Change" button. Make changes to the new change record and click on the "Save" button. The page should redirect to the newly created change record instead of the copied change record.
I hope this helps you achieve your requirement! Let me know if you have any further questions or if there is anything else I can do to assist you.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 04:26 PM
Thankyou for your response. I created the UI script as shared by you. Upon copying a change and clicking Save it redirects me to the change records list view, instead of keeping me on the new change record. I want to stay on the new change record form view upon Save.
I updated the script as below but still the same --
function onLoad() {
if (window.location.pathname.indexOf('/change_request.do') === -1) {
return; // Not on change form
}
var params = new URLSearchParams(window.location.search);
var copyParam = params.get('sysparm_copy');
if (!copyParam) {
return; // Not copying a change
}
var saveButton = document.querySelector('button#sysverb_insert');
if (saveButton) {
saveButton.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default form submission
var form = saveButton.form;
var action = form.action;
var sysId = action.match(/sys_id=([^&]+)/)[1];
var newUrl = '/change_request.do?sys_id=' + sysId; // Redirect to the new change record
window.location.href = newUrl;
});
}
}
Thanks,
Somujit