Solved

Close dialog on complete/cancel

  • 9 March 2017
  • 2 replies
  • 18 views

The problem

I have a problem trying to close a dialog box.

 

Details

1. Page /sites/site1/Pages/Dashboard.aspx opens a dialog box using SharePoint Modal API (SP.UI.ModalDialog.showModalDialog)

2. The dialog opens the url /sites/site1/Lists/OutputRequests/NewForm.aspx

3. K2 redirects the page to https://k2dev.idmdevnet.local/Runtime/Runtime/Form.aspx?_Name=...

 

When the page is successfully submitted or canceled we get "Form submitted successfully" and then the user has to manually close the dialog, which we wanted to be done automatically.

 

- The SharePoint APIs are not longer available since the page is not in the K2 application/domain

- window.close and window.parent.close will throw "Scripts may close only the windows that were opened by it."

- the close window rule doesn't close the dialog

 

Specs

K2 4.16060.2000.1

SharePoint 2013 15.0.4849.1000

 

Related threads

 

SmartForm rule action "close the browser window" leaves the browser tab open to a blank page

http://community.k2.com/t5/K2-blackpearl/SmartForm-rule-action-quot-close-the-browser-window-quot-leaves/td-p/79298

 

Close SmartForm Window

http://community.k2.com/t5/K2-blackpearl/Close-SmartForm-Window/td-p/59409

 

Close SharePoint 2013 Modal Dialog box with Cancel Button

http://community.k2.com/t5/K2-blackpearl/Close-SharePoint-2013-Modal-Dialog-box-with-Cancel-Button/td-p/80305

 

icon

Best answer by jlm 9 March 2017, 18:33

View original

2 replies

managed to do it through postMessage

 

//writer (javascript rule)

parent.postMessage('closeDialog', '*');

 

//listener

window.addEventListener('message', function (event) {

console.log("received: " + event.data);
if (event.data === "closeDialog") {
window.frameElement.cancelPopUp();
}

});

I'm fairly new to K2.  Could you give me a little more information on where this script goes?

 

Thank you

Reply