Unable to close dialog with Public Plumsail Form

Hi all,
I have a public web form which is opened from a SharePoint list display form panel (to add a reply to a helpdesk ticket). The form opens in a dialog but I am not able to automatically close the dialog after the user submits the form.

I have created an "Add Reply" button with the following OnClick:

Dialog.open("https://forms.plumsail.com/xxxxx");

On the JS of the public form, I have the following code:

fd.saved(function(result) {
    Dialog.close(true);
});

However I'm getting an error in the console:

ReferenceError: Dialog is not defined
at eval (eval at e._executeCustomJavaScript (app.js:1), :6:5)
at app.js:4
at Array.map ()
at Function.e.safeRun (app.js:4)
at e. (app.js:1)
at app.js:1
at Object.next (app.js:1)
at a (app.js:1)

Any help is appreciated!

Further - how can we reload the parent form pane so that the data is refreshed?

Hello @atomicharri,

Welcome to Plumsail Community!

It is not possible to interact with the dialog from its internal content if it comes from another domain. But you can post a message to the parent window from the child and handle it.

For this, you need to use window.postMessage() method. Please see the code below.

Use this code in the parent form (SharePoint Form).

fd.spRendered(function() {
    window.addEventListener('message', function (event) {
        if (event.data === "closeDialog") {
            Dialog.close(true);
        }
    });
});

Use this code in child form (Public From).

fd.saved(function(result) {
    window.parent.postMessage('closeDialog', '*');
});

Works perfectly!
Thanks so much!

Also figured out that I can use the .refresh() method directly on the list control directly.

1 Like

Just further to this..
I'm trying to pass variables from the parent to child (helpdesk system and ticketid) so that when the form is submitted, flow knows where to submit the comment to.
Trying the instructions on the Plumsail site, I've got this in the parent form:

window.fd = fd;

and this in the child form (public form):

fd.rendered(function() {

fd.field('SRS').disabled = true;
fd.field('TicketID').disabled = true;

var parentForm = window.top.fd;

if (parentForm) {

    //Set field values with the values from the parent on form load
    fd.field('SRS').value = parentForm.field('ServiceRequestSystem').value;
    fd.field('TicketID').value = parentForm.field('TicketID').value;

}    });

You said that I can't interact parent to child cross domain, does this mean that it won't work.
Is there another way to pass these variables across?

@atomicharri,

You can use the same window.postMessage() method to pass values from SharePoint form to Public form.