How to use 'in' operator in 'or' filter in Fetchxml based report? - ssrs-2008

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

Related

How to exclude some attribute from fetch xml but Retrieve all other attributes

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

Dynamics (FetchXML) - Error: Aggregates are not supported

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)

Fetchxml How to fetch multiple attributes in a groupby fetch (aggregate)

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" />

Xml.IsRuleValid is failing after upgrade from CodeEffects 4.3.7.2 to 5

We are trying to upgrade from CodeEffects 4.3.7.2 to 5. However, our existing rule xml fail when executing CodeEffects.Rule.Common.Xml.IsRuleValid. We are just loading the Xml into an XmlDocument and calling Xml.IsRuleValid. This is all existing and working code in CodeEffects 4. Below is the exception thrown.
Value cannot be null. Parameter name: input
at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings, String baseUri)
at CodeEffects.Rule.Common.RuleXmlValidator.AddSchema(XmlSchemaSet schemas, String schemaName, Assembly assembly)
at CodeEffects.Rule.Common.RuleXmlValidator..ctor()
at CodeEffects.Rule.Common.Xml.IsRuleValid(XmlDocument ruleXml)
Here is a sample xml of a rule now failing in this check. "CustomerSince" and "SystemDate" are DateTime.
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="http://codeeffects.com/schemas/rule/41" xmlns:ui="http://codeeffects.com/schemas/ui/4">
<rule id="ab686e3c-e896-420c-9f8b-5fd09943c939" webrule="4.3.2.71" utc="2016-12-16T07:49:18.9753" type="CompanyABC.Domain.ICustomer, CompanyABC.Domain.State, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<or>
<condition type="isNull">
<property name="CustomerSince" />
</condition>
<condition type="lessOrEqual">
<property name="CustomerSince" />
<property name="SystemDate" />
</condition>
</or>
</definition>
<format><lines /></format>
</rule>
</codeeffects>
I tried using the CodeEffects 5 Classic MVC Rule Editor and generated the below Xml but I still see the same error.
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="http://codeeffects.com/schemas/rule/41" xmlns:ui="http://codeeffects.com/schemas/ui/4">
<rule id="aecdeec9-9b06-4cb1-910d-8b62c311c72f" webrule="5.0.12.4" utc="2020-05-11T22:04:19.8510" type="CompanyABC.Domain.ICustomer, CompanyABC.Domain.State, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<or ui:block="true">
<condition type="isNull">
<property name="CustomerSince" />
</condition>
<condition type="lessOrEqual">
<property name="CustomerSince" />
<property name="SystemDate" />
</condition>
</or>
</definition>
<format><lines /></format>
</rule>
</codeeffects>
We are using the following libraries from CodeEffects Downloader:
CodeEffects.Rule.Common.dll (5.0.4.2)
CodeEffects.Rule.Engine.Standard.dll (5.0.9.6)
And below from Nuget packages:
CodeEffects.Rule.Editor.Mvc.dll (5.0.12.4)
CodeEffects.Rule.Editor.Net.dll (5.0.12.4)
Any assistance would be appreciated.
This issue has been fixed in the latest minor version released earlier today.

Custom Report using Business Intelligence Development Studio FetchXML

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.