cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arjunmusuvathy
Helper III
Helper III

Portal - Child Lookup filter

Hello

 

In my web form I have 2 lookup fields. First lookup looks to a parent entity say Account. Second lookup looks to a child entity say Contacts.

 

When I select 1st lookup (account) record, 2nd lookup (contact) should filter accordingly to show only the contact records where parent = 1st lookup. 

 

I have checked this blog https://www.dancingwithcrm.com/custom-lookup-filtering-powerapps-portal where dependant functionality is possible using "rendering as dropdown" however I would like to maintain the lookups and do the same.

 

I have also checked this blog https://oliverrodrigues365.com/2021/01/24/power-apps-portals-custom-lookup-filter/ where lookups can be restricted to show only certain records which is similar to what I am looking for.

 

I am seeking help to find the exact JS that I am looking for in my scenario.

 

Can anyone advise me please?

 

@OOlashyn @OliverRodrigues 

 

Thanks

Vik

5 REPLIES 5
Fubar
Solution Sage
Solution Sage

Not sure exactly what your overall data structure is, but standard related record lookups work in the Portal (when you don't set the render as dropdown option) - so does your child record contain a lookup to the Account?.

OliverRodrigues
Super User II
Super User II

Hi @arjunmusuvathy how far have you got at this stage?

I think by merging the two articles you should probably get the final code you need.

Have you created your Web Template to return the list of records you need? Once you have that, you can read it via JS, and then loop/remove the unwanted records from the lookup grid.




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

arjunmusuvathy
Helper III
Helper III

@OliverRodrigues 

 

Thanks for your reply. 

 

Below is my web template:

 

{% fetchxml feed %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
- <entity name="contact">
<attribute name="contactid" />
- <filter type="and">
<condition attribute="test_intaccountid" operator="eq" value="{{ request.params['id'] }}" />
</filter>
</entity>
</fetch>
{% endfetchxml %}{
"results": [
{% for item in feed.results.entities %}
{
"Id": "{{ item.}}",
"Name": "{{ item.}}",
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
}



Below is my JS:
I have added a comment in the JS below where I am not sure how to add the fetch results in the lookup.


$(document).ready(function () {
// register on change of Account lookup
$("#test_intaccountid").change(onAccountChange);
$("#test_intaccountid").change();

});

function onAccountChange(){
// get id of selected account field
var accountID = $("#test_intaccountid").val();

if(accountID != null && accountID !=""){
// request to our custom page with id as parameter
$.getJSON( "/categorization-json?id="+accountID, function( data ) {
if(data.results.length>0){

data.results.forEach(element => {
//***NOT SURE HOW TO ADD MY FETCH RESULTS***
});
}
}
);
}
}

 

arjunmusuvathy
Helper III
Helper III

@OliverRodrigues @Fubar  I am closing this ticket down as the OOB dynamics form lookup filtering works in portal. I have a filtering issue in Account lookup but I will comment in my another forum question. Thanks for your time guys.

sorry @arjunmusuvathy .. just seeing this one now

in your fetch, it seems that you are missing the attributes you want to retrieve from the contact entity, please consider adding the attribute tags:

<attribute name="name" />
....

 still in your Liquid, the below seems to be missing the attributes you need to add the attributes there:

"Id": "{{ item.}}",
"Name": "{{ item.}}",

to fetch your data, have you tried the following (once the two things mentioned above are fixed)?:

//***NOT SURE HOW TO ADD MY FETCH RESULTS***
var contactId = element.id;
var contactName = element.name;

 

 




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,590)