Saturday, September 23, 2017

Retrieve EntityImage using SDK

In this example we will retrieve contact entity image

var Contact=Service.Retreive("contact","GUID",new ColumnSet(true));
if(Contact.Attributes.Contains("entityimage"))
{
byte[] entityimage=Contact["entityimage"] as byte[];
}

the above piece of code has no issues and ideally should Retreiveall the attributes of the contact as new ColumnSet(true) is specified but this will not get the entity image 

When you use RetrieveMultiple or Retrieve the EntityImage is not included when the ColumnSet.AllColumns property is set to true. Because of the potential size of data in this attribute, to return this attribute you must explicitly request it.
The binary data representing the image isn’t returned using the deprecated ExecuteFetchRequest class. You should use RetrieveMultipleRequestinstead.

Reference - https://msdn.microsoft.com/en-in/library/dn817886.aspx

Friday, July 7, 2017

SetStateRequest depricated in dynamics 365 online

SetStateRequest being deprecated now in Dynamics 365 (online).
use UpdateRequest to modify specialized fields.

Refer to the below link
https://msdn.microsoft.com/en-us/library/dn932124.aspx

Tuesday, August 23, 2016

CRM 2016 Web API Retrieve Attribute Names By Entity Name

GetEntityMetaData function will retrieve the list of attributes from he Account entity.

 function GetEntityMetaData() {  
   var entityType = "Account";  
   var metaDataId = getMetaDataIdByName(entityType);  
   var schemaNames = getAttributeList(metaDataId);  
 }  
 function getAttributeList(metaDataId) {  
   var attributesList;  
   $.ajax({  
     type: "GET",  
     contentType: "application/json; charset=utf-8",  
     datatype: "json",  
     url: Xrm.Page.context.getClientUrl() + "/api/data/v8.1/EntityDefinitions(" + metaDataId + ")?$select=LogicalName&$expand=Attributes($select=LogicalName)",  
     beforeSend: function (XMLHttpRequest) {  
       XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");  
       XMLHttpRequest.setRequestHeader("OData-Version", "4.0");  
       XMLHttpRequest.setRequestHeader("Accept", "application/json");  
       XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");  
     },  
     async: false,  
     success: function (data, textStatus, xhr) {  
       attributesList = data.Attributes;  
     },  
     error: function (xhr, textStatus, errorThrown) {  
       alert(textStatus + " " + errorThrown);  
     }  
   });  
   return attributesList;  
 }  
 function getMetaDataIdByName(entityType) {  
   var MetadataId;  
   $.ajax({  
     type: "GET",  
     contentType: "application/json; charset=utf-8",  
     datatype: "json",  
     url: Xrm.Page.context.getClientUrl() + "/api/data/v8.1/EntityDefinitions?$select=DisplayName,IsKnowledgeManagementEnabled,EntitySetName&$filter=SchemaName eq '" + entityType + "'",  
     beforeSend: function (XMLHttpRequest) {  
       XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");  
       XMLHttpRequest.setRequestHeader("OData-Version", "4.0");  
       XMLHttpRequest.setRequestHeader("Accept", "application/json");  
       XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");  
     },  
     async: false,  
     success: function (data, textStatus, xhr) {  
       var result = data.value[0];  
       MetadataId = result.MetadataId;  
     },  
     error: function (xhr, textStatus, errorThrown) {  
       alert(textStatus + " " + errorThrown);  
     }  
   });  
   return MetadataId;  
 }  

Monday, February 1, 2016

Retrieve Team Members using RetrieveMultipleRequest

As we know that CRM Sdk deprecated RetrieveMembersTeamRequestmessage (https://msdn.microsoft.com/en-us/library/gg309360.aspx). So there is only way to retrieve Team Members using RetrieveMultipleRequest. and here is the method for the same. It works for the AccessTeam too.


 private static void RetrieveTeamMembers(IOrganizationService service, EntityReference teamEntityReference)  
 {  
 QueryExpression userQuery = new QueryExpression("systemuser");  
 userQuery.ColumnSet = new ColumnSet("fullname");  
 LinkEntity teamLink = new LinkEntity("systemuser", "teammembership", "systemuserid", "systemuserid", JoinOperator.Inner);  
 ConditionExpression teamCondition = new ConditionExpression("teamid", ConditionOperator.Equal, teamEntityReference.Id);  
 teamLink.LinkCriteria.AddCondition(teamCondition);  
 userQuery.LinkEntities.Add(teamLink);  
 EntityCollection retrievedUsers = service.RetrieveMultiple(userQuery);  
 foreach (Entity user in retrievedUsers.Entities)  
 {  
 Console.WriteLine(String.Format("User: {0} with GUID {1}", user.GetAttributeValue<string>("fullname"),  
 user.Id));  
 }  
 }  

Tuesday, July 28, 2015

CRM 2011/2013/2015 Javascript: Get Logged in User Full Name

CRM 2011

 function getUserFullName() {  
   var serverUrl = getCrmServerUrl();  
   var userRequest = GetRequestObject();  
   userRequest.open("GET", serverUrl + "/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')?$select=FullName", false);  
   userRequest.setRequestHeader("Accept", "application/json");  
   userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");  
   userRequest.send();  
   if (userRequest.status === 200) {  
     var retrievedUser = JSON.parse(userRequest.responseText).d;  
     var userFullName = retrievedUser.FullName;  
     return userFullName;  
   }  
   else {  
     return "";  
   }  
 }  
 function getCrmServerUrl() {  
   if (Xrm.Page.context.getClientUrl) // CRM 2011 UR 12+ and CRM 2013  
   {  
     serverUrl = Xrm.Page.context.getClientUrl() + "/";  
   }  
   else // CRM 2011 UR 11 or below  
   {  
     serverUrl = Xrm.Page.context.getServerUrl();  
   }  
   // Adjust URL for differences between on premise and online  
   if (serverUrl.match(/\/$/)) {  
     serverUrl = serverUrl.substring(0, serverUrl.length - 1);  
   }  
   return serverUrl + "/XRMServices/2011/OrganizationData.svc";  
 }  
 function GetRequestObject() {  
   if (window.XMLHttpRequest) {  
     return new window.XMLHttpRequest;  
   }  
   else {  
     try {  
       return new ActiveXObject("MSXML2.XMLHTTP.3.0");  
     }  
     catch (ex) {  
       return null;  
     }  
   }  
 }  


CRM 2013/2015

Xrm.Page.context.getUserName()

Thursday, July 9, 2015

How to Analyze the Performance of Dynamics CRM

The Performance Tool offers a simple and efficient method to analyze (and improve) the performance of Microsoft Dynamics CRM online and on premise environments.
You do need to have CRM 2013 SP1(or above) or 2015. It can be used on both forms and views.
The following steps activates this hidden feature.
Open a CRM form from your browser (IE or Chrome). For example, open an Account form.
Press Ctrl + Shift + Q to view the performance analyzer. This analyzer pop up window appears on your browserAnalyze Performance of CRM
To activate the tool, click the Enable button.
Press F5 to refresh your CRM form. The Performance analyzer will close.
Press Ctrl + Shift + Q to open the performance analyzer
Analyze performance of Dynamics CRM

What does this mean?

The different sections are all code that is triggered prior to a user having a functioning form to work on.
When an environment has many customizations, plug-ins, business rules, iframes or subgrid on a form, this is a great way to determine how quickly it is loading.The time is a breakdown of milliseconds.
In addition to the graphical view, when you click the “Select Major” button you’ll also see the breakdown in a text format.
  • Form Load Start (> 0 ms)
  • Read-Ready (> 1272 ms)
  • Initialize Controls – ViewportInlineEditControlInitializer (> 4583 ms)
  • Initialize Controls – NonViewportFormBodyInlineEditInitializer (> 4954 ms)
  • Initialize Controls – DeferredQuickFormInlineEditInitializer (> 5106 ms)
  • Onload Handler Start (> 5406 ms)
  • Onload Handler Finish (> 5579 ms)
  • Form Full Controls Init (> 5663 ms)
Finally, it is a good idea to disable the tool by clicking the “Disable” button when you have completed your analysis.