Источник:
http://crmscape.blogspot.com/2018/03...t-queries.html
==============
I recently had to create a rollup display showing all activities under a given entity. Pulling the sender or receiver out of an email activity requires a few steps.
Adding confusion the email entity has a text field
ToRecipients which is an accumulated convenience text field. I would avoid using it as it is not complete if an email is sent to an email address that is not associated with a CRM contact, user etc. In this case the
ToRecipients field will be null and the activity party
AddressUsed field must be evaluated.
To fully reach the sender and receivers of email activities from an
ActivityPointer query, the REST query needs to expand to include the
activitypointer_activity_parties link table. You will need the
ParticipationTypeMask to find out the role of each related activityparty, and both the
AddressUsed and
PartyId attributes.
Below is a sample query for all activities (
ActivityPointer) related to an entity.
function retrieveActivities() { var caseId = AllCases[ProcessCaseIndex].Id; var parameters ="$select=ActivityId, RegardingObjectId, Subject, ActivityTypeCode, CreatedOn, ScheduledStart, Description, StateCode, OwnerId"; var expandParameters =",activitypointer_activity_parties/ParticipationTypeMask,activitypointer_activity_parties/PartyId,activitypointer_activity_parties/AddressUsed "; var expand ="&$expand=activitypointer_activity_parties"; var filter ="&$filter=RegardingObjectId/Id eq (guid'"+ caseId +"')"; var orderby ="&$orderby=CreatedOn"; var options = parameters + expandParameters + expand + orderby + filter; SDK.REST.retrieveMultipleRecords("ActivityPointer", options, retrieveActivitiesCallBack, function (error) { alert(error.message); }, activitiesRetrieveComplete);}
The
ActivityPointer.
ActivityTypeCode specifies the activity types:- email, appointment, phonecall, task, letter, fax, serviceappointment, campaignactivity, bulkoperation
- caseresolution, opportunityclose, quoteclose, campaignresponse
The ParticipationTypeMask specifies the activity party role.
1 From, 2 To, 3 CC, 4 BCC, Owner 9, Regarding 8, and a number of others.
In the following code snipet we are just looking for the Sender or From activity party for email activities. The
PartyId.Name is used if available otherwise it looks at the
AddressUsed field, but this field is used in all the other email activity parties (From, To, CC, BCC).
<div class="wlWriterEditableSmartContent" contenteditable="false" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:eb73170f-1539-46b4-a46c-f2e93c4a4a88" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><div>
function retrieveActivitiesCallBack(retrievedActivities) { for (var i =0; i <span style="color: black;">