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

Desmo
Mega Guru

Hello,

I found similar articles, but unable to find a solution.

My use case:

  1. User clicks link from a list, launching a form in a new browser tab
  2. User fills out form
  3. User clicks Save
  4. 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.

4 REPLIES 4

Shubham Tipnis
Kilo Sage

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

Regards,
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.

Hi Shubham,

Thanks for the suggestion. I tried the script for non Workspace. Unfortunately, it does not work.

 

Regards,

Desmo

Prasad Pagar
Mega Sage

Hi @Desmo ,

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

Anil Lande
Kilo Patron

Hi,

Please check below thread, they have suggested a possible way to do it as there is no straightforward way:

https://community.servicenow.com/community?id=community_question&sys_id=b55f3835db40a70467a72926ca96...

 

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande