Javascript and Dialogs (Parent - Child - Grand Child)

I have some special use cases and am having issues with the Dialog JS object.

When I use Dialog.open from a Form to open a Custom Dialog, things work great. However, when I have use cases, where I open a Dialog from a Child Form, I get issues with the object references.

My Scenario:

  • I have Form1 in "full screen".
  • I have Form2 opened from a List/Library control on Form1.
    ** Note the if I do Dialog.getArgs() in console I references Form2
  • I have a Custom Dialog (open with Dialog.open(....) from a Button on Form 2.
    ** If I do Dialog.getArgs() in console now, it references the Custom Dialog
  • In the JS on Custom Dialog, I want to "talk" to the JS on Form 2, but when I do parent. I get the JS on Form 1

I have tried to window.opener from the Custom Dialog, but the value is always null.

Again, my question is: From the Custom Dialog, how do I access the JS in Form2?

Dear @sphilson,
Try adding the following line to Form 2:
window.top.fd2 = fd;

Then you can access it from Form 3, with the following code:
window.top.fd2.field('Title').value

I made something similar... I have a form (say Form1.New) in web part and I can open a child form (Form2), I set window.fd=fd in parent and I can get correctly any value I want to pass.

I also can open this parent Form1 in edit as a child form (Form1.edit) in dialog mode and from the Form1.Edit I can open Fomr2.New. In this way I have a Parent, Child, GrandChild structure

I set in Form1.edit window.top.fd2 = fd, and I can get correctly any value I want from parent and set it in grand-child.

When close grandchild and child and I open Form2.new from Form1.New (only parent and child), I don't get Form1.New values but I get the last value I set in precedence in grandchild. If I reload the page it doesn't happen until the next time I do again the whole process.

I'm using this code:

var parentForm = window.top.fd;
var parentForm2 = window.top.fd2;

alert(parentForm.formId);
alert(parentForm2.formId);

if (window.top.fd2) {
  do something
}
else {
if (window.top.fd) {
  do something else
}

I saw that var parentForm2 = window.top.fd2;, once initialized, maintain his value until I reload the page even if I close the window.

Any Idea?

Perhaps reset the parentForm2 value to blank?

Dear @Fritz77,
So what's the current behavior? And what's the expected behavior? If parent is not the top window, it's also possible to use this:

window.parent.fd = fd;
  1. I have The New Form in webpart (FormA.New), from list control in this form I can open another form (FormB) as dialog and I populate this second form with some first value correctly.

  2. from the same new form (FormA.New) in webpart I can open the same form but in edit mode (FormA.Edit) in dialog and I can open from this second form the FormB. FormB was populated correctly from FormA.Edit and save this FormB and FormA.edit. I'm using an IF condition to check if FORM B has a FormA.Edit as parent form or FormA.New as parent.

  3. later, if open FormB form FormA.New, it was populate with the last value at point 2. and not with the correct value

if I reload the page between 2. and 3. then 3. correctly works.

I tried a lot of configuration to check the parent form id but is the same for FormA.New and FormB.Edit, I tried to check which form type has the parent, if new or edit but the problem is that after saving in 2. and close FormB and FormA.Edit, values remain in storage.

If I check which form is parent and which is top I find the same FormA.Edit even if I closed it. I think that when in webpart, dialog forms, even closed, remain in some ways

Dear @Fritz77,
What way are you using to retrieve values from the top form? We might need to see the exact configuration, and also how the forms are opened. I would recommend recording a video with all the details and sending it to support@plumsail.com if possible. We need to see the code, and how and when the forms are opened.

It's quite a complicated setup, have you tried checking form type like so:

if (window.parent.fd.formType == 'Edit'){
  //do something
}

Yes I tried but returns the same value for top and parent also if they are different. I think the web part maintains some values

Hi @Fritz77,

We couldn't replicate the issue so far. Please export your form and send it to support@plumsail.com along with a video of the problem.