Dynamics Advanced Find on 2 entities - dynamics-crm

I want to do an advanced find on a field on the Contact form and also a field from an extension entity but want to do an OR rather than an AND but it doesn't seem to let me. I want to make a marketing list picking both of these fields.

You could try a calculated field on your extension entity that references the field from the Contact. I assume your extension entity has a lookup to Contact. So create a new calculated field on the extension entity of the same type as the field on Contact that you need. The calculation will be "contact.fieldname" where "contact" is the name of the lookup relationship and "fieldname" is the field on the contact that you need.
Now the calculated field on the extension entity will contain the same data from the field on the Contact and you can use Advanced Find to "OR" these two fields together since they are on the same entity.

I think you can do this with an aliased condition
This is done by:
Giving your Link Entity an alias value
Create an or filter
In your condition, specify the entityname which is a reference to the Link Entity's alias
For example, this query will retrieve Contact's First and Last Names and the Account's Name where either the Contact or the Account is active (as an inner join)
<fetch top="50" >
<entity name="contact" >
<attribute name="firstname" />
<attribute name="lastname" />
<filter type="or" >
<condition attribute="statecode" operator="eq" value="0" />
<condition entityname="ParentAccount" attribute="statecode" operator="eq" value="0" />
</filter>
<link-entity name="account" from="accountid" to="parentcustomerid" alias="ParentAccount" >
<attribute name="name" />
</link-entity>
</entity>
</fetch>
So in this example-query you can see:
Account is the Link Entity and I've given it the "ParentAccount" alias
The filter is applied to the Contact entity and the Link Entity has no criteria
The condition for the Account Status specifies the "ParentAccount" entityname

Related

How to fetch users not in a specific queue/team?

I have a task to create a custom grid view of users not in a specific team.
I created the fetch according to team (entity) not equal to my specific team but I didn't get the wanted results after recheck I changed it from team to Queue and still no good results, is there an option to get the needed results using Fetch
In Dynamics 2016 you cannot do this using FetchXml.
In Dynamics 365 this is possible. It would look like this:
<fetch attribute="teamid" operator="eq" value="00000000-0000-0000-0000-000000000000" >
<entity name="systemuser" >
<attribute name="fullname" />
<filter>
<condition entityname="teammembership" attribute="teamid" operator="null" />
</filter>
<link-entity name="teammembership" from="systemuserid" to="systemuserid" link-type="outer" >
<attribute name="teamid" />
<filter>
<condition attribute="teamid" operator="eq" value="4212a8d9-4893-eb11-b1ac-000d3adb2ab1" />
</filter>
</link-entity>
</entity>
</fetch>
The condition doing the trick here is <condition entityname="teammembership" attribute="teamid" operator="null" />, where you specify the entity that is the right part in the left outer join.
As said, you cannot do this in Dynamics 2016, so you have no other option than executing the query above without its first filter and do the filtering on the resultset returned by the query.

How can I get 'which updated fields can trigger to Dynamics CRM workflow'?

I have a custom workflow activity.
The workflow has been triggered by one of 10 specific fields updated.
I need these 10 fields what are they in my custom workflow. Is there any way I can get this information in custom workflow?
Edited After Aron's comment:
I try Aron's solution. It works, but some fields are missing.
For example, I have 7 fields (include the address field) to trigger my workflow as below.
But TriggerOnUpdateAttributeList has only 4 fields as below.
The Workflow entity has a field called TriggerOnUpdateAttributeList which contains what you're looking for.
One way to access it would be a FetchXML query:
<fetch top="1" >
<entity name="workflow" >
<attribute name="name" />
<attribute name="primaryentity" />
<attribute name="triggeronupdateattributelist" />
<filter>
<condition attribute="name" operator="eq" value="My Workflow" />
<condition attribute="triggeronupdateattributelist" operator="not-null" />
</filter>
</entity>
</fetch>
In the result, the TriggerOnUpdateAttributeList contains a comma separated list of the logical names of the fields:
<result>
<name>My Workflow</name>
<primaryentity name="" formattedvalue="2">2</primaryentity>
<triggeronupdateattributelist>firstname,lastname,parentcustomerid</triggeronupdateattributelist>
</result>

FetchXML Query to fetch columns from multiple Linked Entity

Scenario: There is a portal which shows data in grid and this data comes from Dynamics 365. Being Dynamics developed I have been requested to provide a query which will show data in below format
for Example, Phone call can be associate with either Contact or CustomAccount(Custom Entity) and CustomAccount has lookup of Contact on its form. We require all the Phone Call records but there is a catch. When fetching Phone Call for contact, we need to fetch field value of contact like Residential Address, Mailing Address, Email Address, Phone Numbers. it is doable. But if the Phone call associated with CustomAccount entity, then we have to fetch contact associated with CustomAccount Entity and then its fields like Residential Address, Mailing Address, Email Address, Phone Numbers.
I tried building query but its result is weird and showing only Phone Calls associated with CustomAccount entity and not contact entity.
<fetch>
<entity name='phonecall' >
<all-attributes/>
<link-entity name='contact' from='contactid' to='regardingobjectid' link-type='outer' alias='contact' >
<all-attributes/>
</link-entity>
<link-entity name='pref_CustAccount' from='pref_CustAccountid' to='regardingobjectid' link-type='outer' alias='account' >
<link-entity name='contact' from='contactid' to='lpl_clientid' link-type='inner' alias='accountcontact' >
<all-attributes/>
</link-entity>
</link-entity>
</entity>
</fetch>
I just replicated your scenario on my CRM instance. I think your problem is with Link type for below line.
<link-entity name='contact' from='contactid' to='lpl_clientid' link-type='inner' alias='accountcontact' >
you need outer rather than inner.
When I gave inner I got only those records related to above line.
Here is my complete fetch
<fetch>
<entity name="phonecall" >
<link-entity name="contact" from="contactid" to="regardingobjectid" link-type="outer" alias="directcontact" >
<attribute name="fullname" />
</link-entity>
<link-entity name="account" from="accountid" to="regardingobjectid" link-type="outer" alias="account" >
<link-entity name="contact" from="contactid" to="primarycontactid" link-type="outer" alias="primarycontact" >
<attribute name="fullname" />
</link-entity>
</link-entity>
</entity>
</fetch>

FetchXML - Find records not linked to specific record via N:N

There are numerous posts for finding "not-in" to find records of type a that have no associations to record type b.
I want to extend this in my scenario I have a Database record type and a Server Upgrade record type with an N:N between them. (there is an N:N between database and server but that's not part of this query)
I want to find all database records that are not already linked to the specific server upgrade I am working on. My attempts are failing because the database can be linked to other server upgrade records
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
<entity name="dsg_databases" >
<attribute name="dsg_databasesid" />
<filter type="and" >
<condition entityname="ae" attribute="dsg_serverupgradeid" operator="neq" value="25dbe565-f435-e911-a976-000d3a2bcd97" />
</filter>
<link-entity name="dsg_dsg_serverupgrade_dsg_databases" from="dsg_databasesid" to="dsg_databasesid" link-type="outer" intersect="true" >
<link-entity name="dsg_serverupgrade" from="dsg_serverupgradeid" to="dsg_serverupgradeid" link-type="outer" alias="ae" />
</link-entity>
</entity>
</fetch>
The reason being, in a plugin I then associate these databases to the server upgrade record but get an error Cannot insert duplicate key if they are already linked.
For reference and in case there's a better way, I take the entity collection returned by the FetchXML, convert to an EntityReferenceCollection ercDatabases and use service.Associate(targetEntity.LogicalName, targetEntity.Id, relationship, ercDatabases);
Edit - I'm trying to avoid cycling through each database record returned and checking whether they're associated. I'd rather do it in the single query for performance.
Moving the filter condition of the recordid you're trying to exclude to the intersect entity (ensuring it's an outer join) and ignoring the second join to the actual server upgrade record, then having a condition in the main entity filter pointing to the join record checking for null appears to work
<fetch top="50" >
<entity name="dsg_databases" >
<attribute name="dsg_databasesid" />
<attribute name="dsg_name" />
<filter type="and" >
<condition entityname="ae" attribute="dsg_serverupgradeid" operator="null" />
</filter>
<link-entity name="dsg_dsg_databases_dsg_server" from="dsg_databasesid" to="dsg_databasesid" visible="false" intersect="true" >
<link-entity name="dsg_server" from="dsg_serverid" to="dsg_serverid" alias="ad" >
<filter type="and" >
<condition attribute="dsg_serverid" operator="eq" value="98f46447-7f7b-e811-a95a-000d3a22cba0" />
</filter>
</link-entity>
</link-entity>
<link-entity name="dsg_dsg_serverupgrade_dsg_databases" from="dsg_databasesid" to="dsg_databasesid" link-type="outer" intersect="true" alias="ae" >
<filter type="and" >
<condition attribute="dsg_serverupgradeid" operator="eq" value="25dbe565-f435-e911-a976-000d3a2bcd97" />
</filter>
</link-entity>
</entity>
</fetch>

Fetch XML returns 0 records where there is no related field

I'm using FetchXML to retrieve some field values for a few given IDs. The problem is that if I request a related field, and that field does not have a value, no records are returned.
For example, in using the following FetchXML, the Accounts for the given IDs do exist but since they DO NOT have a ParentAccount no values are returned.
<fetch mapping="logical">
<entity name="account">
<attribute name="name" />
<attribute name="ownerid" />
<link-entity name="account" to="parentaccountid" alias="parentaccountid">
<attribute name="name" />
</link-entity>
<filter>
<condition attribute="accountid" operator="in">
<value>9c8539fd-f7b1-e811-a973-000d3af4a510</value>
<value>be76ea1b-f8b1-e811-a973-000d3af4a510</value>
<value>1e76ea1b-f8b1-e811-a973-000d3af4a510</value>
<value>50843103-f8b1-e811-a973-000d3af4a510</value>
<value>b983ea1b-f8b1-e811-a973-000d3af4a510</value>
</condition>
</filter>
</entity>
</fetch>
Is there something I need to add to the link-entity to indicate that if it is null to still return the rest of the values?
You can mention join to be an outer if that field will be null for some records.
<link-entity name="account" to="parentaccountid" alias="parentaccountid" link-type="outer">
Read more

Resources