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

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>

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.

Dynamics Advanced Find on 2 entities

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

Dynamics 365 subject tree not updating case dropdown

When I update subject tree with new subjects or change subjects, I do not see it reflected in the case subject dropdown. I can go back into the subject tree and I see my changes are there and saved.
How do I get my Subject tree changes to show in the case subject dropdown?
Make sure you don't have any custom subject attribute, looking at the native subject tree relation in incident.
I will start digging the subject in XrmToolbox - FetchXml Builder for any discrepancy in data like featuremask (need to be 1). We cannot check this in Adv.Find as Subject is not searchable, also if you are in on-premise do the SQL way.
<fetch top="50" >
<entity name="subject" >
<attribute name="description" />
<attribute name="featuremask" />
<attribute name="subjectid" />
<attribute name="versionnumber" />
<attribute name="modifiedby" />
<attribute name="createdby" />
<attribute name="modifiedon" />
<attribute name="title" />
<attribute name="createdon" />
<attribute name="organizationid" />
<attribute name="parentsubject" />
</entity>
</fetch>
I was having this exact same issue. I added a couple of new subjects and they weren't appearing on the Case form. To resolve this I went to: Settings > Customizations > Customize the System. I then published all customizations and the new subjects started appearing on the Case form.

FetchXml query generates a 'Generic SQL Error' but works if I switch the linked entities around?

I'm attempting to query the product catalog of a "vanilla" CRM 2015, my final aim is to retrieve the active products by price list and substring of name, at the moment I'm hard-coding my data as follows:
PriceLevel: hardcoded GUID
Name: hardcoded "a"
The resulting XML is this:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" count="50">
<entity name="productpricelevel" >
<attribute name="uomid" />
<filter type="and">
<condition attribute="pricelevelid" operator="eq" uitype="pricelevel" value="{7080964d-85df-e411-80ba-00155d0b0c38}" />
</filter>
<link-entity name="product" from="productid" to="productid" alias="ac" >
<attribute name="name" />
<attribute name="productnumber" />
<order attribute="productnumber" descending="false" />
<filter type="and">
<condition attribute="name" operator="like" value="a" />
<condition attribute="statecode" operator="eq" value="0" />
</filter>
</link-entity>
</entity>
</fetch>
When I attempted to execute the query, I got Generic SQL Error. I then looked at the trace logs, and found this:
Exception when executing query: select DISTINCT "productpricelevel0".UoMId as "uomid", "productpricelevel0".UoMIdName as "uomidname",
coalesce("LL0".Label,"ac".Name ) as "ac.name", "ac".ProductNumber as "ac.productnumber"
from ProductPriceLevel as "productpricelevel0" join Product as "ac"
on ("productpricelevel0".ProductId = "ac".ProductId and ( coalesce("LL0".Label,"ac".Name) like 'a' and "ac".StateCode = 0))
left outer join BusinessDataLocalizedLabel as "LL0" on ("LL0".ObjectId = "ac".ProductId and "LL0".LanguageId = 1033 and "LL0".ObjectColumnNumber = 6 )
where ("productpricelevel0".PriceLevelId = '7080964d-85df-e411-80ba-00155d0b0c38') order by
"ac".ProductNumber asc
Exception: System.Data.SqlClient.SqlException (0x80131904): The multi-part identifier "LL0.Label" could not be bound
In an attempt to identify a pattern, I switched the JOIN around, ending up with this XML:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" count="50" >
<entity name="product" >
<attribute name="name" />
<attribute name="productnumber" />
<order attribute="productnumber" descending="false" />
<filter type="and" >
<condition attribute="name" operator="like" value="a" />
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<link-entity name="productpricelevel" from="productid" to="productid" alias="ac" >
<attribute name="uomid" />
<filter type="and" >
<condition attribute="pricelevelid" operator="eq" uitype="pricelevel" value="{7080964d-85df-e411-80ba-00155d0b0c38}" />
</filter>
</link-entity>
</entity>
</fetch>
This time, I got my results as expected, no errors.
The organization is new and only contains Sitemap/HTML/JS customizations (the entities I'm querying are not customized yet), 1033 is the base language, there is another language installed and enabled but it isn't used by any of the 2 users of the system.
What's going on in the first case ?
UPDATE: The first query works against a 2013 organization. This is starting to feel like a bug.
This definitely is a bug. I guess Microsoft changed the engine that converts QueryBase queries into T-SQL.
This week we had an issue with linked entities. It was about the following condition:
.AddCondition("statuscode", ConditionOperator.In, new object[] { 1, 2, 3 });
When applied on the primary entity of a QueryExpression, the condition is processed as expected. When applied on a linked entity it fails. In previous versions of Dynamics CRM it works in both scenarios.

Can you write a single FetchXML query to get 1:many relationship?

Is it possible to write a single FetchXML query that gets a root entity and multiple children? All I've been able to do is 1:1.
James Wood is correct. Fetch XML is recursive so by using the link entity you can get the information you want.
For example, the following is valid:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<order attribute="name" descending="false" />
<link-entity name="contact" from="parentcustomerid" to="accountid" alias="aj">
<attribute name="firstname" />
<attribute name="lastname" />
<attribute name="telephone1" />
<link-entity name="businessunit" from="businessunitid" to="owningbusinessunit" alias="ak">
<attribute name="name" />
<attribute name="address1_line1" />
<attribute name="address1_line2" />
<attribute name="address1_line3" />
<filter type="and">
<condition attribute="name" operator="not-null" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
If your question really is "Is it possible to write a single FetchXML query that gets a SINGLE root entity and multiple children" then the answer is unfortunately no. However if you are able to handle duplicates of root data (For example using the Grouping functionality of an SSRS report) then what you require is entirely possible
Unless I've misunderstood the question this is very possible.
So for example you want to find all the contacts related to a given account. This is represented in Crm by the Parent Customer Lookup on the contact to the account.
<fetch mapping="logical" count="100" version="1.0">
<entity name="account">
<attribute name="name" />
<link-entity name="contact" from="parentcustomerid" to="accountid">
<attribute name="fullname" />
</link-entity>
</entity>
</fetch>
Which gives you a result set that looks like this:
<resultset morerecords="0" paging-cookie="<cookie page="1"><accountid last="{E704FAD6-2D4B-E111-9FED-00155D828444}" first="{AD912122-6B3C-E111-9B37-00155D828444}" /></cookie>">
<result>
<name>RGD Mining Inc</name>
<accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
<accountid.fullname>Bill Miner</accountid.fullname>
</result>
<result>
<name>RGD Mining Inc</name>
<accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
<accountid.fullname>Green</accountid.fullname>
</result>
</resultset>
No, it is not possible.
I'm happy to report that it is possible. I have a solution that worked well for me.
The only caveat is that if you have multiple child accounts you will get multiple results for the parent. For example:
parent 1: child 1
parent 2: child 1
parent 2: child 2
This means that you would then have to run the results through a sorting function, to get either all the children under parents in a multi dimensional array, or get all the accounts as unique entries in a flat array.
Also, this only goes down one level. If your hierarchy is multi-level, this code would need to be modified.
<fetch distinct="false" mapping="logical">
<entity name="account">
<attribute name="name" />
<link-entity name="account" alias="childaccount" to="accountid" from="parentaccountid" link-type="outer">
<attribute name="name" alias="childname" />
</link-entity>
</entity>
</fetch>

Resources