I'm fairly new to the FetchXML / Dynamics scene so please excuse my ignorance.
Up until now I've been executing a PowerShell Script that runs a FetchXML query to obtain user most recent login dates within Dynamics.
This has been working flawlessly for about a month, but as of about a week ago the script stopped accepting my FetchXML query throwing an error saying "Aggregates are not supported".
No changes to the code have been made what so ever.
Weirdly, the exact same code worked in the UAT Dynamics environment but not in production. After a couple more days it appears that it's stopped working in the UAT environment too.
Any ideas as to why this could be occurring? I'll post the code below.
Thanks All
$xml = [string]::Format('
<?xml version="1.0" encoding="UTF-8"?>
<fetch mapping="logical" aggregate="true" version="1.0">
<entity name="audit">
<attribute name="createdon" alias="lastlogin" aggregate="max" />
<attribute name="auditid" alias="lastloginct" aggregate="count" />
<filter>
<condition attribute="operation" operator="eq" value="4" />
<condition attribute="createdon" operator="on-or-after" value="{0}" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="objectid" alias="su" link-type="inner">
<filter>
<condition attribute="domainname" operator="eq" value="{1}" />
</filter>
<attribute name="fullname" alias="fullname" groupby="true" />
<attribute name="firstname" alias="FirstName" groupby="true" />
<attribute name="lastname" alias="LastName" groupby="true" />
<attribute name="domainname" alias="domainname" groupby="true" />
<attribute name="accessmode" alias="accessmode" groupby="true" />
<attribute name="isdisabled" alias="isdisabled" groupby="true" />
<attribute name="businessunitid" alias="businessunitid" groupby="true" />
<attribute name="internalemailaddress" alias="internalemailaddress" groupby="true" />
<attribute name="systemuserid" alias="ObjectID" groupby="true"/>
<attribute name="ms_provider" alias="Provider" groupby="true"/>
<attribute name="mobilephone" alias="Mobile" groupby="true"/>
</link-entity>
</entity>
</fetch>
', $date, $user.userprincipalname)
Related
I want to retrieve all attributes of entity but exclude some of them.
Like if entity have 42 attributes I want to exclude Name, Date and retrieve all others. Below is what i have tried.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
<entity name="account" >
<all-attributes/>
!<attribute name="name" />!
<order attribute="statecode" descending="false" />
<filter type="and" >
<condition attribute="statecode" operator="eq" value="0" />
<condition attribute="location" operator="eq" uitype="location" value="{11c43ee8-b9d3-4e51-b73f-bd9dda66e29c}" />
</filter>
</entity>
</fetch>
You should remove <all-attributes/> node and add all the attributes you want into the fetchXML.
The fetchXml should look like:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
<entity name="account" >
<attribute name="a"/>
<attribute name="b"/>
<attribute name="c"/>
<attribute name="d"/>
<order attribute="statecode" descending="false" />
<filter type="and" >
<condition attribute="statecode" operator="eq" value="0" />
<condition attribute="location" operator="eq" uitype="location" value="{11c43ee8-b9d3-4e51-b73f-bd9dda66e29c}" />
</filter>
</entity>
</fetch>
Here are some ways to generate a fetchXml:
Download from Advance find. You can download the fetchXml after you added the columns and conditions you want.
Use the FetchXML Builder.
Use Dataverse REST Builder
I have a fetchxml which worked fine until I added another attribute to the fetch.
<attribute name="ey_b_closed_conversations" alias="isClosed" />
this is the line I added to the fetch, and now it doesn't work.
The following code is the complete fetchxml.
<fetch mapping="logical" version="1.0" aggregate="true" distinct="false">
<entity name="ey_case_branch_callcenter_inquiry">
<attribute name="ey_s_name" alias="count" aggregate="countcolumn" />
<attribute name="ey_p_action" alias="id" groupby="true" />
<attribute name="ey_b_closed_conversations" alias="isClosed" />
<filter>
<condition attribute="ey_case_sub_subjectid" operator="eq" value="{9E52CB8E-BEA6-E411-AFFF-0050568C0143}" />
<condition attribute="statecode" operator="eq" value="0" />
</filter>
</entity>
</fetch>
Are there any limitations on the number of attributes I can fetch in an aggregated fetchxml?
How can I add my additional (non-aggregated) attribute to the fetch?
Are there any limitations on the number of attributes I can fetch in an aggregated fetchxml?
No.
How can I add my additional (non-aggregated) attribute to the fetch?
You cannot.
You might have received this error: An attribute can not be requested when an aggregate operation has been specified and its neither groupby nor aggregate.
This is similar to SQL error: Column 'xxxx' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
This error is coming because the below line in your query does not have either groupby or aggregate property in the line.
<attribute name="ey_b_closed_conversations" alias="isClosed" />
Referring this community post:
This is because when you group by you can only include an attribute that you are not grouping-by as an aggregate ( E.g sum/min/max/count)
I tested the below and it worked:
<fetch mapping="logical" version="1.0" aggregate="true" distinct="false" >
<entity name="account" >
<attribute name="name" alias="count" aggregate="countcolumn" />
<attribute name="telephone2" alias="phone" groupby="true" />
<attribute name="telephone1" alias="mobile" aggregate="count" />
<attribute name="accountnumber" alias="number" groupby="true" />
<filter>
<condition attribute="statecode" operator="eq" value="0" />
</filter>
</entity>
</fetch>
SQL equivalent:
SELECT count(name) AS count,
count(telephone1) AS mobile,
telephone2 AS phone,
accountnumber AS number
FROM account
WHERE statecode = 0
GROUP BY telephone2, accountnumber
So either do this:
<attribute name="ey_b_closed_conversations" alias="isClosed" aggregate="count" />
or
<attribute name="ey_b_closed_conversations" alias="isClosed" groupby="true" />
I am using following xml in an Fetch based report in SSRS for Dynamics 365. I've allowed #transaction parameter to null but rest of the both parameters must have values. So, I put an or condition so that if #transaction is null or 0 then on the base of 1 and 2 grab the orders. I've total 10 records but they are not being shown or the report preivew show 0 records. Any idea how to resolve this?
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorder">
<attribute name="salesorderid" />
<attribute name="ordernumber" />
<order attribute="ordernumber" descending="true" />
<filter type="and">
<condition attribute="new_transaction" operator="eq" value="#transaction" />
<condition attribute="createdon" operator="on-or-before" value="#To" />
<condition attribute="createdon" operator="on-or-after" value="#From" />
</filter>
<filter type="or">
<condition attribute="new_transaction" operator="in" >
<value>1</value>
<value>2</value>
</condition>
</filter>
</entity>
</fetch>
If I understood correctly, you can replace your filter like below to get result.
<filter type="and">
<condition attribute="createdon" operator="on-or-before" value="#To" />
<condition attribute="createdon" operator="on-or-after" value="#From" />
<filter type="or">
<condition attribute="new_transaction" operator="in" >
<value>1</value>
<value>2</value>
</condition>
<condition attribute="new_transaction" operator="eq" value="#transaction" />
</filter>
</filter>
Pro tips:
1.Build the query in Advanced find, test the result & Download fetchxml from there to use in report.
2.If you write SQL query, transform it to fetchxml using Kingswaysoft sql2fetchxml free online converter.
3.Read this article to transform fetchxml into Adv find query.
<filter type="or">
<condition attribute="new_transaction" operator="in" value=#parm>
</condition>
</filter>
*work for multiple values
I am having issues with a FetchXML query running against Dynamics CRM 2013 (online).
When running this simple query
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="5">
<entity name="activitypointer">
<attribute name="activityid" alias="activity_id" />
<attribute name="activitytypecode" alias="activity_type" />
<attribute name="ownerid" alias="owner" />
</entity>
</fetch>
I get the expected results for the activity_type column e.g. "email", "opportunityclose" etc.
But when I attempt this aggregate version of the same query
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
<entity name="activitypointer">
<attribute name="activityid" alias="activity_count" aggregate="count" />
<attribute name="activitytypecode" alias="activity_type" groupby="true" />
<attribute name="ownerid" alias="owner" groupby="true" />
</entity>
</fetch>
I get the correct results for the activity_count and owner columns, but the "activity_type" column is populated with just "Microsoft.Xrm.Sdk.OptionSetValue" or if ran within a report "#error".
I assume this is something to do with grouping by an option field type.
Does anyone know how to resolve this issue?
You have to be very careful when it comes with nulls and grouping. Try adding a filter that excludes null values. I have verified in 2011 that it does return a valid value for Option Sets.
I want to create a custom report which will display all associated Products of all/any Order. That means in Order page its showing all Orders and associated Products, and in any Order record page it should display only the Products associated with that Order.
Previously I did that using report wizard.It was working as I wanted.
But I am not able to do it in Business Intelligence Development Studio.
this is the FetchXML
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorderdetail">
<attribute name="productid" />
<attribute name="productdescription" />
<attribute name="priceperunit" />
<attribute name="quantity" />
<attribute name="extendedamount" />
<attribute name="salesorderdetailid" />
<order attribute="productid" descending="false" />
<link-entity name="salesorder" from="salesorderid" to="salesorderid" alias="ad">
<filter type="and">
<condition attribute="salesorderid" operator="eq">
</condition>
</filter>
</link-entity>
</entity>
</fetch>
How I can modify this XML so that it will work like above?
Finally, I am able to do it, using sub query.
This it the Sub query fetchXML:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorderdetail">
<attribute name="productid" />
<attribute name="productdescription" />
<attribute name="priceperunit" />
<attribute name="quantity" />
<attribute name="extendedamount" />
<attribute name="salesorderdetailid" />
<order attribute="productid" descending="false" />
<link-entity name="salesorder" from="salesorderid" to="salesorderid" alias="af">
<filter type="and">
<condition attribute="salesorderid" operator="eq" uitype="salesorder" value="#salesorderid"/>
</filter>
</link-entity>
</entity>
</fetch>
and this is the fetchXML of the main query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorder" enableprefiltering="1">
<attribute name="name" />
<attribute name="salesorderid" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="ownerid" operator="eq-userid" />
<condition attribute="statecode" operator="in">
<value>0</value>
<value>1</value>
</condition>
</filter>
</entity>
</fetch>
Hope this will help someone.