Multiple cascading cross site lookup parent child autopopulation

rss

Posted by mcgaafar - Mar 26 ’16 at 05:09

Hi,

 

I have a form with the following cross site lookups:

Client(lookup accounts list), Contact(lookup contacts list and filtered according to selected client "cascading').

 

On the same form i have two other cascading lookups:

Contractor(lookup accounts list), Contact(lookup contacts list and filtered according to selected contractor "cascading').

 

All above mentioned fields have "add new" link, currently i'm using the following code to populate the  company field on the child form with the client value on the parent form:

 

if (window.top != window.self){

var companyID=window.top.fd.field('Client').value();

var companyData=window.top.fd.field('Client').control('data')['Title'];

fd.field('Company').value({Id: companyID, Title: companyData});

}

 

The code is working fine, however i can't figure out how to update that code so that the child form can distinguish between the Client and Contractor and populate the company accordingly.

 

Appreciate your help.

  • mcgaafar
    Member
    Member for: 4 years 1 month 7 days
    #1 by mcgaafar Mar 28 ’16 at 06:35

    Hi, anyone here?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 9 months 20 days
    #2 by rostislav Mar 28 ’16 at 06:48

    [#1]:

    I don't get it. Just use the internal name of the contractor field?

  • mcgaafar
    Member
    Member for: 4 years 1 month 7 days
    #3 by mcgaafar Mar 28 ’16 at 09:29

    While having two different cascading lookup field sets on the parent form every set has a link (add new contact) to the same child form (contacts form). The question is:

    If the user selected the client and didn't add its cascading contact, then selected the contractor but didn't add its cascading contact, then clicked on the "add new contact" for the client, how would the child form know whether to populate its "Company" field with the client value or the contractor value from the parent?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 9 months 20 days
    #4 by rostislav Mar 28 ’16 at 09:58

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 9 months 20 days
    #5 by rostislav Mar 28 ’16 at 10:00

    [#4]:

    I see. What you can do is set a global variable when you click your 'add new' links. Then in your code on the child form check the variable, do your stuff and then reset it to its initial state.

    So, on your parent form:

    fd.field('csl').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'client'});
    
    fd.field('csl2').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'company'}); 

    This adds an onlick handler for the links.

    On your child form then just reference myvar. Note, think of a better name, so that some other code doesn't override it.

     

  • mcgaafar
    Member
    Member for: 4 years 1 month 7 days
    #6 by mcgaafar Mar 28 ’16 at 11:35

    [#5]: Thanks a lot for your response and your proposed solution, it's not working for me, i guess i'm not fully understanding you. Please check my code, appreciate if you let me know how to fix it.

     

    Here's the code that i used on the parent form:

    fd.field('Contact').control()._el().find('a[href^="http"]').click(function(){window.myParentCompany = 'Client'});

    fd.field('MEPContact').control()._el().find('a[href^="http"]').click(function(){window.myParentCompany = 'MEPContractor'});

     

    And here's the one i'm using on the child (contacts) form:

    if (window.top != window.self){

    var companyID=window.top.fd.field(myParentCompany).value();

    var companyData=window.top.fd.field(myParentCompany).control('data')['Title'];

    fd.field('Company').value({Id: companyID, Title: companyData});

    }

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 9 months 20 days
    #7 by rostislav Mar 28 ’16 at 12:09

    [#6]:

    You seem to be doing everything right, except two things:

    1. you need to access myParentCompany via window.top: window.top.myParentCompany

    2. don't forget to do delete window.top.myParentCompany after you've set the field -- although maybe don't *have* to do it since you're checking that window.top != window.self, but still, probably better do it

  • mcgaafar
    Member
    Member for: 4 years 1 month 7 days
    #8 by mcgaafar Mar 28 ’16 at 04:01

    I couldn't get it to work out.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 9 months 20 days
    #9 by rostislav Mar 29 ’16 at 05:36

    [#8]:

    Actually, no, you're not doing it correctly. You didn't understand the code I posted.

    fd.field('csl').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'client'});

    Adds myvar to the topmost window object with value 'client' when you click 'add new' in a cross site lookup field 'csl'. Analogously,

    fd.field('csl2').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'contractor'});

    Adds (or rewrites) myvar to the topmost window object with value 'contractor' when you click 'add new' in a cross site lookup field 'csl2'.

    So, on your child form you can access the variable and see if it is 'client' or 'contractor' and do your code logic based on this. So something like this (obviously you need to check internal names, etc - this is just code to give you an idea of what to do):

    if (window.top != window.self){
        if (window.top.myvar === 'client') {
            var companyID=window.top.fd.field('Client').value();
            var companyData=window.top.fd.field('Client').control('data')['Title'];
        } else if (window.top.myvar === 'contractor') {
            var companyID=window.top.fd.field('Contractor').value();
            var companyData=window.top.fd.field('Contractor').control('data')['Title'];
        }
        fd.field('Company').value({Id: companyID, Title: companyData});
        delete window.top.myvar;
    } 

     

     

Displaying 1 to 9 of 9 messages