How to get value of Child Item in Related Items View

rss

Posted by Jdubs - Dec 3 ’15 at 06:05

When opening up a New form from a Related Items view, I'm using the following code to populate the Child item from the Parent item:

//Populate fields from existing related item (**This Works**)

fd.field('HireDate').value(window.top.fd.field('HireDate').value());

fd.field('BeginningBalance').value(window.top.fd.field('BeginningBalance').value());

fd.field('Points').value(window.top.fd.field('Points').value());

 

However, populating a Child item from the newly created Parent Item does not work.

Scenario:

1.  Edit existing item [#1] (works)

2.  Create New item  [#2] in Related View from the Edit Item [#1] (works)  **fields in item [#2] form pre-populate correctly**

3.  The newly created item [#2] appears in the Related Items view in item [#1] (works)

4. Edit newly created item [#2] from Related View while still in the original Edit item [#1] (works)

5. Create New item [#3] in Related View from the Edit Item [#2] (there are now two pop up windows open) (works)

6. **Does Not Work** item [#3] is populating fields from item [#1] instead of item [#2] from where it is being created.

 

Hope that makes sense.  Let me know if you have any questions.

 

Thanks!!!

  • rostislav
    rostislav
    Moderator
    Member for: 6 years 5 months 24 days
    #1 by rostislav Dec 4 ’15 at 07:49

    The reason for that is that window.top references the topmost window. You'll need to iterate through all iframes (embedded html documents) and compare with the source URL parameter to get the appropriate iframe

    window.top.Plumsail.FD.jQuery('iframe').each(function(i) {
    
    	if (this.contentWindow.document.location.href == GetUrlKeyValue('Source')){
    
    		fd.field('HireDate').value(this.contentWindow.fd.field('HireDate').value());
    
    		// etc..
    
    	}
    
    }); 
  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #2 by Jdubs Dec 22 ’15 at 12:11

    [#1]: Didn't work :(

     

    This is my code:

     

    window.top.Plumsail.FD.jQuery('iframe').each(function(i) {

     

    if (this.contentWindow.document.location.href == GetUrlKeyValue('Source')) {

    fd.field('HireDate').value(this.contentWindow.fd.field('HireDate').value());

    fd.field('Employee').value(this.contentWindow.fd.field('hiddenEmployeeNameValue').value());

    fd.field('BeginningBalance').value(this.contentWindow.fd.field('BeginningBalance').value());

    fd.field('Points').value(this.contentWindow.fd.field('Points').value());

    }

    });

     

    Thanks Rostislav!

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #3 by Dmitry Kozlov Dec 23 ’15 at 04:28

    [#2]: Hi,

    What version of Forms Designer do you use? You can find it in the lower right corner of the designer.

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #4 by Jdubs Jan 6 ’16 at 09:15

    [#3]: I'm on version 3.0.1.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #5 by Dmitry Kozlov Jan 7 ’16 at 04:03

    [#4]: Hi,

    Add tracing to your code to ensure that the parent frame is found:

    window.top.Plumsail.FD.jQuery('iframe').each(function(i) {
    	if (this.contentWindow.document.location.href == GetUrlKeyValue('Source')) {
    		alert('The IFRAME was found');
    		...
    	}
    });
    

    Also, ensure that no errors appear in the browser console (F12)

Displaying 1 to 5 of 5 messages