Multiple cascading cross site lookup parent child autopopulation

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

26 Mar 2016

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
Posts: 44
Joined: Sun Jan 17, 2016

28 Mar 2016

Hi, anyone here?

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

28 Mar 2016

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

mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

28 Mar 2016

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?

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

28 Mar 2016

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.

mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

28 Mar 2016

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

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

28 Mar 2016

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
Posts: 44
Joined: Sun Jan 17, 2016

28 Mar 2016

I couldn't get it to work out.

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

29 Mar 2016

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

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests