UI Action: Save & Close [save record, close browser tab]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2021 10:43 AM
Hello,
I found similar articles, but unable to find a solution.
My use case:
- User clicks link from a list, launching a form in a new browser tab
- User fills out form
- User clicks Save
- Record is saved and user remains the same browser tab
Note: Clicking Submit redirects user back to the list, but in the same browser tab
I've added a Save & Close UI action with the following script:
function closeWindow(){
g_form.save();
window.open('','_self').close();
}
The action quickly closes the window, however, it does not save the record.
FYI. I've posted the same question in an existing post. However, in order for community members to get proper credit [Mark as Correct Answer], then a new post is most appropriate.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2021 02:22 AM
Hi Desmo,
Found below sample code of workspace in docs. See if you could create a similar one for your requirement
In the Workspace Client Script field, add the following client script UI Action to save the contents of the tab and close it.
function onClick(g_form) {
g_form.save().then(function(){
g_aw.closeRecord();
});
}
https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/workspace/task/close-tab-ui-action.html
Please mark correct/helpful if applicable.
Regards,
Shubham
Shubham Tipnis
ServiceNow Enthusiast
⭐️ 3x Rising Star (2022–2024) – ServiceNow Community
Sharing insights, use cases & real-world learnings from the Now Platform
Always learning. Always building.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2021 08:03 PM
Hi Shubham,
Thanks for the suggestion. I tried the script for non Workspace. Unfortunately, it does not work.
Regards,
Desmo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2021 09:05 PM
Hi
Just thinking why can't you use OOB Submit button and its script for your custom form?
Did you tried it already?
Thank you
Prasad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2021 09:21 PM
Hi,
Please check below thread, they have suggested a possible way to do it as there is no straightforward way:
Thanks,
Anil Lande
Thanks
Anil Lande