CRM 2011 Get Required and Optional Contact Names from ActivityPartySet - dynamics-crm

I am trying to create a report in SSRS for CRM 2011 and I am trying to get information from the AppointmentSet. I am able to get everything expect the Required and Optional Attendees. I'm pretty sure the AppointmentSet links to the ActivityPartySet to for the attendees. But I am not sure. How would you go about getting the required attendees and optional attendees. This is what I have so far.
<fetch>
<entity name="appointment">
<attribute name="scheduledstart" />
<link-entity name="systemuser" from="systemuserid" to="ownerid">
<attribute name="firstname" alias="ownerFirstName" />
<attribute name="lastname" alias="ownerLastName" />
</link-entity>
<link-entity name="contact" from="contactid" to="new_contactperson">
<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">
<attribute name="participationtypemask" alias="participationtypemask" />
</link-entity>
</entity>
</fetch>

I'm not fully clear on your requirements but the following snippet will return full details of Optional or Required attendees, but only if they are system user records. If the parties contain other record types then no results are returned...
<entity name='appointment'>
<attribute name='subject'/>
<attribute name='actualend'/>
<attribute name='actualstart'/>
<filter type='and'>
<condition attribute='activityid' operator='eq' value='MyActivityGuid'/>
</filter>
<link-entity name='activityparty' from='activityid' to='activityid'>
<attribute name='partyidname'/>
<attribute name='participationtypemask'/>
<attribute name='activityid'/>
<attribute name='activitypartyid'/>
<attribute name='addressused'/>
<attribute name='participationtypemaskname'/>
<attribute name='partyid'/>
<attribute name='partyiddsc'/>
<attribute name='partyobjecttypecode'/>
<attribute name='resourcespecid'/>
<attribute name='resourcespeciddsc'/>
<attribute name='resourcespecidname'/>
<attribute name='scheduledend'/>
<attribute name='scheduledstart'/>
<filter type='and'/>
<filter type='or'>
<condition attribute='participationtypemaskname' operator='eq' value='Optional attendee'/>
<condition attribute='participationtypemaskname' operator='eq' value='Required attendee'/>
</filter>
<link-entity name='systemuser' from='systemuserid' to='partyid'>
<attribute name='fullname'/>
</link-entity>
</link-entity>
</entity>
Otherwise if you omit the entire final link-entity node for systemuser you can see the addressused attribute which contains an email address. I.e.:
<entity name='appointment'>
<attribute name='subject'/>
<attribute name='actualend'/>
<attribute name='actualstart'/>
<filter type='and'>
<condition attribute='activityid' operator='eq' value='MyActivityGuid'/>
</filter>
<link-entity name='activityparty' from='activityid' to='activityid'>
<attribute name='partyidname'/>
<attribute name='participationtypemask'/>
<attribute name='activityid'/>
<attribute name='activitypartyid'/>
<attribute name='addressused'/>
<attribute name='participationtypemaskname'/>
<attribute name='partyid'/>
<attribute name='partyiddsc'/>
<attribute name='partyobjecttypecode'/>
<attribute name='resourcespecid'/>
<attribute name='resourcespeciddsc'/>
<attribute name='resourcespecidname'/>
<attribute name='scheduledend'/>
<attribute name='scheduledstart'/>
<filter type='and'/>
<filter type='or'>
<condition attribute='participationtypemaskname' operator='eq' value='Optional attendee'/>
<condition attribute='participationtypemaskname' operator='eq' value='Required attendee'/>
</filter>
</link-entity>
</entity>
Does this help?

Related

Fetch XML SSRS Report

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.

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>

Join/Filter syntax for activity pointers using fetchxml

I have a requirement to pass in a fetch statement for a subgrid to use in CRM 2013. It needs to get the following:
All Activities regarding contacts who are connected to a contact through a connection. (This statement gets those)
<?xml version="1.0" encoding="UTF-8"?>
<fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="modifiedon" />
<attribute name="instancetypecode" />
<attribute name="scheduledend" />
<attribute name="actualend" />
<attribute name="regardingobjectid" />
<attribute name="activityid" />
<order descending="false" attribute="modifiedon" />
<link-entity name="contact" to="regardingobjectid" from="contactid">
<link-entity name="connection" to="contactid" from="record1id">
<filter type="and">
<condition attribute="record2id" value="someID" uitype="contact" operator="eq" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
All activities regarding opportunities related to the contact. ((This statement gets those))
<?xml version="1.0" encoding="UTF-8"?>
<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="modifiedon" />
<attribute name="instancetypecode" />
<attribute name="scheduledend" />
<attribute name="actualend" />
<attribute name="regardingobjectid" />
<attribute name="activityid" />
<order descending="false" attribute="modifiedon" />
<link-entity name="opportunity" to="regardingobjectid" from="opportunityid">
<filter type="and">
<condition attribute="customerid" value="someID" uitype="contact" operator="eq" />
</filter>
</link-entity>
</entity>
</fetch>
And all activities regarding the contact itself.
I've tried a few different combinations of joins, but I'm not sure I'm getting their positioning or syntax correct. I unfortunately deleted those attempts after they all returned no results. Here is one of the last version I tried which also returned no results.
<?xml version="1.0" encoding="UTF-8"?>
<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="modifiedon" />
<attribute name="instancetypecode" />
<attribute name="scheduledend" />
<attribute name="actualend" />
<attribute name="regardingobjectid" />
<attribute name="activityid" />
<order descending="false" attribute="modifiedon" />
<link-entity name="opportunity" to="regardingobjectid" from="opportunityid">
<attribute name="name" />
</link-entity>
<link-entity name="contact" to="regardingobjectid" from="contactid">
<link-entity name="connection" to="contactid" from="record1id">
<attribute name="record1id" />
</link-entity>
</link-entity>
<filter type="or">
<condition entityname="connection" attribute="record2id" value="" + Xrm.Page.data.entity.getId() + "" uitype="contact" operator="eq" />
<condition entityname="activitypointer" attribute="regardingobjectid" value="" + Xrm.Page.data.entity.getId() + "" uitype="contact" operator="eq" />
<condition entityname="opportunity" attribute="customerid" value="" + Xrm.Page.data.entity.getId() + "" uitype="contact" operator="eq" />
</filter>
</entity>
</fetch>
If anyone can help me out with formatting I'd appreciate it.
Thanks in advance.
It appears to me that although you can now use an OR filter across tables in CRM 2013 (your syntax looks correct) the OR does not apply to the link itself. In SQL terms it is as if you did a full join between the tables and then put the OR logic within the WHERE statement. If any of the joins doesn't match you will return no results.
select *
from activitypointer
join opportunity on ..
join connection on...
join contact on...
WHERE (opportunity.regardingID = SomeID) OR (opportunity.customerid = SomeID) OR (activitypointer.regardingobjectid = SomeID)
In your bottom example your activity must linked BOTH to an opportunity AND to a contact through a connection and one OR the other must meet your criteria within the OR filter. Unfortunately I do not think you can write the fetch you desire but I am not 100% sure of this so if anyone can confirm or refute this please do. This link has a good example of what you can do using OR filters across tables.

FetchXML: get count of records based on a field of a linked entity

I have a scenario where i want to get the count of people from an Entity who have multiple location address marked as current address in other linked entity.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" aggregate="true">
<entity name="client">
<attribute name="clientid"/>
<attribute name="name"/>
<attribute name="createdon"/>
<order attribute="name" descending="false"/>
<link-entity name="locationadd" from="clientid" to="clientid" alias="aa">
<attribute name="locationadd" aggregate="countcolumn" />
<filter type="and">
<condition attribute="isthiscurrentadd" operator="eq" value="1"/>
</filter>
</link-entity>
</entity>
</fetch>
The answer is
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' aggregate='true'>
<entity name='client'>
<attribute name='clientid' alias='PersonName' groupby='true' />
<link-entity name='locationadd' from='clientid' to='clientid' alias='aa'>
<attribute name='isthiscurrentadd' alias='Count' aggregate='count'/>
<filter type='and'>
<condition attribute='isthiscurrentadd' operator='eq' value='1'/>
</filter>
</link-entity>
</entity>
</fetch>
Try following - this code will return you the number of clients.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" aggregate="true">
<entity name="client">
<attribute name="clientid" aggregate='count' alias='clientscount'/>
<link-entity name="locationadd" from="clientid" to="clientid" alias="aa">
<attribute name="locationadd" aggregate="countcolumn" />
<filter type="and">
<condition attribute="isthiscurrentadd" operator="eq" value="1"/>
</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