Fetch XML SSRS Report - dynamics-365

When i create a fetch xml ssrs report using the following fetch xml
<fetch distinct="true" >
<entity name="incident" >
<attribute name="ticketnumber" />
<attribute name="createdon" />
<attribute name="ssg_workedby" />
<attribute name="statuscode" />
<attribute name="ssg_trustid" />
<attribute name="statecode" />
<attribute name="ssg_requestraisedby" />
<attribute name="caseorigincode" />
<attribute name="title" />
<attribute name="createdby" />
<attribute name="ssg_turnaroundtime" />
<attribute name="ownerid" />
<attribute name="ssg_abouttofailfirstsla" />
<attribute name="ssg_abouttofailsecondsla" />
<attribute name="responseby" />
<attribute name="ssg_fixcode2cause" />
<attribute name="ssg_fixcode3owner" />
<attribute name="ssg_queue" />
<filter type="and" >
<condition attribute="createdon" operator="on-or-before" value="03-03-2020" />
<condition attribute="createdon" operator="on-or-after" value="01-01-2020" />
<filter type="or" >
<condition attribute="subjectidname" operator="eq" value="Complaint" />
<condition attribute="subjectidname" operator="eq" value="Failure in process" />
<condition attribute="subjectidname" operator="eq" value="Governance" />
<condition attribute="subjectidname" operator="eq" value="Time to resolve" />
</filter>
<filter type="or" >
<condition attribute="statecode" operator="eq" value="0" />
<condition attribute="statecode" operator="eq" value="1" />
</filter>
</filter>
<order attribute="createdon" />
<link-entity name="incidentresolution" from="incidentid" to="incidentid" link-type="outer" alias="CaseResolution" visible="true" >
<attribute name="actualend" />
<attribute name="subject" />
<filter type="and" >
<condition attribute="statuscode" operator="eq" value="2" />
</filter>
</link-entity>
</entity>
</fetch>
There are columns such as "statecode" which gets repeated 2 times. Please refer the screenshot for more information. Is there any way to reduce these two columns to only one?

This is because SSRS SSDT (Reporting Services) provides with State Code Value (0/1) and State Code (Active/Inactive).
In your report you are using both of them. You will need to remove any one depending on what you want.
Note: You do not need to change any thing in fetchxml, rather in Report builder just remove a column of Value or Name.

Related

How Can I Find All Workflows Using a Custom Workflow Step

I have a custom workflow step registered into Dynamics 365 CE. How can I find all workflows that contain that workflow step?
A code-free way is
Navigate to Settings > Customizations
Click on "Customize the System"
Expand Plugin Assemblies
Select the assembly that contains your custom workflow step
Select the custom workflow step (i.e. check the box)
Click Show Dependencies
Credit to this post: https://community.dynamics.com/365/f/dynamics-365-general-forum/366932/find-a-specific-step-in-workflow
The gist of the answer is to write FetchXML to examine the xaml attribute of the workflow entity.
E.g. looking for the plugin Example.WorkflowStep
<fetch distinct="true" >
<entity name="workflow" >
<attribute name="createdon" />
<attribute name="primaryentity" />
<attribute name="statecode" />
<attribute name="workflowid" />
<attribute name="ownerid" />
<attribute name="type" />
<attribute name="owningbusinessunit" />
<attribute name="name" />
<attribute name="category" />
<attribute name="xaml" />
<filter type="and" >
<condition attribute="type" operator="eq" value="1" />
<condition attribute="statecode" operator="eq" value="1" />
<filter type="and" >
<condition attribute="rendererobjecttypecode" operator="null" />
<condition attribute="xaml" operator="like" value="%Example.WorkflowStep%" />
</filter>
</filter>
<order attribute="primaryentity" />
</entity>
</fetch>

FetchXML query to return all records owned by subordinates of current user

I have a org that uses Managerial hierarchy to organize Employees (Users). They'd like a view for managers. This view should return all Open Opportunities owned by Users who are managed by the current user, OR managed by someone who is managed by the current user, OR managed by someone who is managed by someone who is managed by the current user. These 3 levels is are all that we need.
I've already developed a FetchXML query that returns all Projects owned by Users who are managed by the current user.
<entity name="opportunity">
<attribute name="name" />
<attribute name="estimatedvalue" />
<attribute name="statuscode" />
<attribute name="parentcontactid" />
<attribute name="parentaccountid" />
<attribute name="opportunityid" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="owninguser" link-type="inner" alias="ad">
<filter type="and">
<condition attribute="parentsystemuserid" operator="eq-userid" />
</filter>
</link-entity>
</entity>
</fetch>
Below is an alternative that also doesn't work. This returns all Opportunities that are owned by someone who is managed by current user, which manages them self.
<entity name="opportunity">
<attribute name="name" />
<attribute name="estimatedvalue" />
<attribute name="statuscode" />
<attribute name="parentcontactid" />
<attribute name="parentaccountid" />
<attribute name="opportunityid" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="owninguser" link-type="inner" alias="aa">
<filter type="and">
<condition attribute="parentsystemuserid" operator="eq-userid" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="parentsystemuserid" link-type="inner" alias="ab">
<filter type="and">
<condition attribute="parentsystemuserid" operator="eq-userid" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="parentsystemuserid" link-type="inner" alias="ac">
<filter type="and">
<condition attribute="parentsystemuserid" operator="eq-userid" />
</filter>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
You might be interested in the following owner operators:
eq-useroruserhierarchy
eq-useroruserhierarchyandteams
eq-useroruserteams
eq-userteams
From your description you might want eq-useroruserhierarchy
You use it like this:
<fetch top="50" >
<entity name="opportunity" >
<all-attributes/>
<filter>
<condition attribute="ownerid" operator="eq-useroruserhierarchy" />
</filter>
</entity>
</fetch>

fetchXml Dynamics 365 with sorting on link entity and paging working only for first page, not others

following query is working fine for first page
<fetch count="10" no-lock="true" page="1">
<entity name="account">
<attribute name="accountid" />
<attribute name="name" />
<link-entity name="contact" from="parentcustomerid" to="accountid" link-type="outer" alias="contact">
<attribute name="contactid" />
<attribute name="fullname" />
<attribute name="jobtitle" />
<attribute name="emailaddress1" />
<attribute name="telephone1" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="telephone3" />
<attribute name="mobilephone" />
<attribute name="statuscode" />
<attribute name="statecode" />
<order attribute="lastname" />
</link-entity>
</entity>
</fetch>
the same query for second page gives only one record
<fetch count="10" no-lock="true" page="2">
<entity name="account">
<attribute name="accountid" />
<attribute name="name" />
<link-entity name="contact" from="parentcustomerid" to="accountid" link-type="outer" alias="contact">
<attribute name="contactid" />
<attribute name="fullname" />
<attribute name="jobtitle" />
<attribute name="emailaddress1" />
<attribute name="telephone1" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="telephone3" />
<attribute name="mobilephone" />
<attribute name="statuscode" />
<attribute name="statecode" />
<order attribute="lastname" />
</link-entity>
</entity>
</fetch>
No idea, What is wrong with second and onward page request?
If I remove the order attribute from link entity then it is working fine.
Are you using a paging cookie? That will not work in this case, where there are multiple rows returned for each account.
When not to use paging cookies
Paging cookies depend on the common case where each row returned represents a unique entity record. There
are some queries you can construct using link-entity that will provide
rows that combine data from the primary entity with related entities.
This will result in multiple primary entity rows that refer to the
same primary key value. If you depend on paging cookies in this
situation you will get inconsistent results.
My preferred way to fix this issue is to "flip" your query around: Make contact your primary entity and link to account instead (presuming this would be a suitable query for you). Your query would then look as follows:
<fetch count="10" no-lock="true" page="1">
<entity name="contact">
<attribute name="contactid" />
<attribute name="fullname" />
<attribute name="jobtitle" />
<attribute name="emailaddress1" />
<attribute name="telephone1" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="telephone3" />
<attribute name="mobilephone" />
<attribute name="statuscode" />
<attribute name="statecode" />
<order attribute="lastname" />
<link-entity name="account" from="accountid" to="parentcustomerid" link-type="outer" alias="account">
<attribute name="accountid" />
<attribute name="name" />
</link-entity>
</entity>
</fetch>

MS CRM: How can I query for phone calls without Recipient ("Call To")

Wie imported a bunch of phoneCalls via Excel in our MS CRM 2013 system but for some of them the recipient (Call To) field were not set. Now we want to query for those records via FetchXml. How can we do this?
I tried the following, but it I received a lot of Phone Calls with recipient. Can you help?
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
<entity name="activitypointer" >
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="instancetypecode" />
<attribute name="createdon" />
<attribute name="regardingobjectid" />
<attribute name="ownerid" />
<attribute name="activityid" />
<attribute name="prioritycode" />
<attribute name="scheduledend" />
<attribute name="createdby" />
<order attribute="createdon" descending="true" />
<order attribute="activitytypecode" descending="false" />
<filter type="and" >
<condition attribute="modifiedby" operator="eq-userid" />
<condition attribute="activitytypecode" operator="eq" value="4210" />
</filter>
<link-entity name="systemuser" from="systemuserid" to="owninguser" alias="activitypointerowningusersystemusersystemuserid" >
<attribute name="internalemailaddress" />
</link-entity>
<link-entity name="activityparty" from="activityid" to="activityid" link-type="outer" alias="ab" >
<filter type="and" >
<condition attribute="activitypartyid" operator="null" />
<condition attribute="participationtypemask" operator="eq" value="2" />
</filter>
</link-entity>
</entity>
</fetch>
I think you should try.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="phonecall">
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="prioritycode" />
<attribute name="scheduledend" />
<attribute name="createdby" />
<attribute name="regardingobjectid" />
<attribute name="activityid" />
<order attribute="subject" descending="false" />
<link-entity name="activityparty" from="activityid" to="activityid" alias="ab">
<filter type="and">
<condition attribute="participationtypemask" operator="eq" value="2" />
<condition attribute="partyid" operator="null" />
</filter>
</link-entity>
</entity>
</fetch>

Query CRM 2011 with Outer Join

I am using the code below to query the appointment set in CRM 2011. When I use this query it returns the data, but it returns duplicates. If I take out the Outer joins it doesn't return anything at all. Any ideas on how to fix this?
<fetch>
<entity name="appointment">
<attribute name="scheduledstart" />
<link-entity name="systemuser" from="systemuserid" to="ownerid" link-type="outer">
<attribute name="firstname" alias="ownerFirstName" />
<attribute name="lastname" alias="ownerLastName" />
</link-entity>
<link-entity name="contact" from="contactid" to="new_contactperson" link-type="outer">
<attribute name="parentcustomerid" alias="parentaccount" />
<attribute name="new_businessunit" alias="businessunit" />
</link-entity>
<attribute name="new_contactperson" />
<attribute name="subject" />
<attribute name="new_coldernotes" />
<link-entity name="activityparty" from="activityid" to="activityid" link-type="outer">
<attribute name="participationtypemask" alias="participationtypemask" />
<filter>
<condition attribute="participationtypemask" operator="eq" value="5" />
</filter>
<link-entity name="contact" from="contactid" to="partyid" link-type="outer">
<attribute name="fullname" alias="RequiredContactFullName" />
</link-entity>
<link-entity name="systemuser" from="systemuserid" to="partyid" link-type="outer">
<attribute name="fullname" alias="RequiredOwners" />
</link-entity>
<link-entity name="account" from="accountid" to="partyid" link-type="outer">
<attribute name="name" alias="RequiredAccount" />
</link-entity>
</link-entity>
<!--the new join-->
<link-entity name="activityparty" from="activityid" to="activityid" alias="optionalactivityparty" link-type="outer">
<attribute name="participationtypemask" alias="optionalparticipationtypemask" />
<filter>
<condition attribute="participationtypemask" operator="eq" value="6" />
</filter>
<link-entity name="contact" from="contactid" to="partyid" alias="optionalcontact" link-type="outer">
<attribute name="fullname" alias="OptionalContactFullName" />
</link-entity>
<link-entity name="systemuser" from="systemuserid" to="partyid" alias="systemuser2" link-type="outer">
<attribute name="fullname" alias="OptionalOwners" />
</link-entity>
<link-entity name="account" from="accountid" to="partyid" alias="optionalaccount" link-type="outer">
<attribute name="name" alias="OptionalAccount" />
</link-entity>
</link-entity>
<filter type="and">
<condition attribute="scheduledstart" operator="on-or-after" value="#FromDate" />
<condition attribute="scheduledstart" operator="on-or-before" value="#ToDate" />
</filter>
</entity>
</fetch>
Thanks!
Try indicating that you want a distinct record set by changing your root fetch node to
<fetch distinct='true'>
...
</fetch>

Resources