Multiple cascading cross site lookup parent child autopopulation
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.
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.
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?
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?
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:
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.
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.
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:
And here's the one i'm using on the child (contacts) form:
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'});
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});
}
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
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
Actually, no, you're not doing it correctly. You didn't understand the code I posted.
Adds myvar to the topmost window object with value 'client' when you click 'add new' in a cross site lookup field 'csl'. Analogously,
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
fd.field('csl').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'client'});
Code: Select all
fd.field('csl2').control()._el().find('a[href^="http"]').click(function(){window.myvar = 'contractor'});
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;
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 10 guests