Page 1 of 1

Multiple cascading cross site lookup parent child autopopulation

Posted: 26 Mar 2016
by mcgaafar
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.

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by mcgaafar
Hi, anyone here?

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by rostislav
I don't get it. Just use the internal name of the contractor field?

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by mcgaafar
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?

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by rostislav
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:

Code: Select all

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.

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by mcgaafar
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:

Code: Select all

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:

Code: Select all

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});
}

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by rostislav
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

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 28 Mar 2016
by mcgaafar
I couldn't get it to work out.

Re: Multiple cascading cross site lookup parent child autopopulation

Posted: 29 Mar 2016
by rostislav
Actually, no, you're not doing it correctly. You didn't understand the code I posted.

Code: Select all

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,

Code: Select all

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):

Code: Select all

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;
}