Asked by:
How to get 'to' and 'from' of phone activity of Contact using OData?

Question
-
Hi,
I have successfully created 'Phone Call Activity' for a contact. Now I want to list (programatically) all the activity related to 'to' and 'from' of particular contact. I should also be able to filter data using different parameter.
I am using 'PhoneCallSet' to get list of all phone call activity.
Regards
- Edited by Pranit P Kothari Thursday, November 6, 2014 12:27 PM
Thursday, November 6, 2014 12:17 PM
All replies
-
1.Add Json and Jquery as Web resource as first and you can find it in CRM SDK at following path sdk\samplecode\js\restendpoint\restjquerycontacteditor\restjquerycontacteditor\scripts
2.Pass parameter sender and Recipients
3. Make Query on PhoneCallSet Entity as
a)Sender eq " Name of Sender",
b)Recipient eq "Name of Recipient" and Regarding eq "Name of Contact" Using Odata Query Designer Tool
function phoneCalls_onloadContact() { var contactId = Xrm.Page.data.entity.getId() ? Xrm.Page.data.entity.getId() null; if (contactId != null) { var phoneCalls =GetPhoneCallByContact(contactId); if (phoneCalls != null && phoneCalls[0].results.length > 0) { for (var count = 0; count < phoneCalls[0].results.length; count++) { alert(phoneCalls[0].results[count].from); alert(phoneCalls[0].results[count].to); } } } } function GetPhoneCallByContact(contactId) { var serverUrl = Xrm.Page.context.getServerUrl(); var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/PhoneCallSet?$select=from,RegardingObjectId,to&$filter=from eq '"+Sender Name+"' and to eq '"+RecipientName+"' and RegardingObjectId/Id eq guid'" + contactId + "'"; var jSonArray = new Array(); jQuery.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: oDataUri, async: false, beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { if (data && data.d != null) { jSonArray.push(data.d); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { alert("Error : has occured during retrieval of the contacts"); } }); return jSonArray; }
Muhammad Sohail
- Edited by sohail450 Thursday, November 6, 2014 1:19 PM
- Proposed as answer by Jithesh Karumampatty Kalam Friday, November 7, 2014 4:18 AM
Thursday, November 6, 2014 1:17 PM -
PhoneCallSet does not have 'to' and 'from' attributes. When I try to run query by selecting 'to'/'from' page give error - 400Friday, November 7, 2014 4:04 AM
-
please install odata query designer to build the right query.
http://crm2011odatatool.codeplex.com/
Jithesh
Friday, November 7, 2014 4:18 AM -
Tool is really good. But I am still getting error 400. I used very simple query,
http://someurl/xrmservices/2011/OrganizationData.svc/PhoneCallSet?$select=from,to
If I do not use $select=from,to .. it just works fine
Friday, November 7, 2014 4:41 AM -
Hi Pranit,
I was not aware of this. Learnt a new thing today. Thanks.
See this link. I have executed the query and it works. may be it gets more info that you may need.
https://crm2011odatatool.codeplex.com/workitem/502
Regards,
Friday, November 7, 2014 5:03 AM -
Can you specifically get 'to' and 'from' from it? I am not able to get those. Even not in some other param.Friday, November 7, 2014 6:03 AM