Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Linked-Entity in addCustomFilter

At this moment I know how to use the addCustomFilter in combination with addPreSearch (and the remove variants). All this works perfectly when passing a filterXml like:

<filter type="and">
  <condition attribute="name" operator="eq" value="test123" />
</filter>

But I just can't figure out how to use linked-entities in the addCustomFilter and whether it is actually possible. I've tried the following:

<link-entity name="account" from="accountid" to="parentaccountid">
  <filter type="and">
    <condition attribute="name" operator="eq" value="test123" />
  </filter>
</link-entity>

It is still the same filter but it is now placed on the parent account of the account. With this filterXml I want to get all the accounts that have the account 'test123' as the parent account.

The problem is that the filter doesn't work in the addCustomFilter but it does return results in the AdvancedFind.

Is there a way to use linked-entities in the addCustomFilter method, if so what am I doing wrong?

like image 481
user3687899 Avatar asked May 29 '14 14:05

user3687899


People also ask

What is linked entity in MS CRM?

Linked entity is basically a relationship between entities. Example relationship of Account & Contact: CRM has out of box (1:N )relationship between Account & Contact. Contact has 'ParentCustomerId' field as foreignkey of 'Account' entity.

How do I get layout XML in CRM?

Select your View. Assuming, you have an Advanced Find view open in the window which you want as a layoutXml of, on the same, press F12 to open Dev Tools. Select the selector. Click on it, and the par will be selected in the Console of the Dev Tools.


1 Answers

addCustomFilter method takes two parameters filter and the entityLogicalName. The entityLogicalName is optional and if this parameter is provided, the filter will only apply to that entity type. Otherwise it will apply to all types of entities returned.

For e.g. customer lookup control display account and contact records. If we don't provide the entityLogicalName parameter, the filter will apply to both account and contact records and if we provide 'account' as a parameter then filter will only be applied to account records not to contact records.

So ...

if we are using another related entity (as with your example) as the filter, it is using <linked-entity>,

  • which is not allowed in the .addCustomFilter() method.

BUT There is a way ..

actually the only way is still using the MSCRM 2011 Code, that is using .addCustomView() with its many parameters (using your own fetchXml & layoutXml).

Xrm.Page.getControl(arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)
like image 197
Shane_Yo Avatar answered Sep 28 '22 23:09

Shane_Yo