Announcements
Hi All.
I want to retrieve child data based on the selected parent record for the below scenario. I am using Dynamics 365.
On a custom entity for example entity 'A', I have two lookup field for entity 'B' and entity 'C', where entity 'B' is a custom entity and entity 'C' is out of box entity and Entity 'B' and entity 'C' having relationship as 1:N.
if 'B' record is selected on the entity 'A' form then it should display the related records of 'C' and if no 'B' record is selected then there should be no records shown for 'C"
Can anybody have a suggestion on this .
Regards,
Richa
Hi Bipin,
Thank you very much for your reply.
Let me implement this and revert back.
Regards
Richa
Hi,
I have written the code for you -
function setParentAccountIdFilter(executionContext) {
// get the form context
formContext = executionContext.getFormContext();
formContext.getControl("msft_company").addPreSearch(function (){
// get Entity 'B' Lookup field value
var contact = formContext.getAttribute("msft_emergencycontact").getValue();
var contactId="{00000000-0000-0000-0000-000000000000}";
var contactName="Dummy Contact";
if(contact!=null)
{
contactId=contact[0].id;
contactName=contact[0].name;
}
var fetchQuery = "<filter type='and'><condition attribute='primarycontactid' operator='eq' uiname='" + contactName + "' uitype='contact' value='" + contactId + "' /></filter>";
formContext.getControl("msft_company").addCustomFilter(fetchQuery,"account");
});
}
msft_emergencycontact -> Entity B Lookup field schema name
msft_company -> Entity C lookup field schema name
account -> Entity C Name
contact -> Entity B Name
primarycontactid -> Entity B lookup field on Entity C
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Hi Bipin,
Thanku for your Reply.
As i am not very experienced with coding in CRM so will you mind if i ask you to elaborate more on this.
Thanks in Advance!
Regards,
Richa
Hi,
Okay. In that case you can use Addcustomfilter client api to achieve your requirement -
So in fetch xml condition you will add {00000000-0000-0000-0000-000000000000} guid if B is not select and if B is selected the you will pass in the selected record guid.
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Hi Bipin,
Yes entity 'c' has a lookup for entity 'b' but the requirement is to show no records for 'b' if user doesn't select any 'c' record at first. This i want to achieve it through JS.
Thank you!
Regards,
Richa
Hi Richa,
Are you referring to something like this where Category only displays lookup values from the associated Area entity and the Issue lookup only display values linked to the value selected in Category?
Hi,
Does Entity 'C' has lookup of Entity 'B'. If yes then you can achieve your filtering with OOB related record configuration-
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156