Tuesday, March 13, 2018

Error Connecting to Dynamics 365 Online from Report Viewer in VS

After entering connection details the connection dialog prompts for the credentials multiple times and this is because of the recent changes by Microsoft to he overall platform

ROOT CAUSE:
Its all because of the latest update in the Microsoft TSL(Transport Security Layer) Protocol in SDK assemblies..Microsoft allowed the TSL connection 1.0  and 1.1 for the browsers or client to connect the CRM org.Now Microsoft will support only TSL 1.2 or above going forward(Reference) . If you are connecting your org with the old version of plugin registration tool , then you may face this issue.


Uninstall Report Authoring Extension and install the latest.(Make sure Installed dll is the latest SDK 9.0). if this doesnt resolve the issue then follow the below step.


On the machine where VS is installed go to the start menu, then type run and then enter. Type in regedit and then OK.

Once the Registry Editor is open, go to: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319
Right click on the name of the folder (the v4.0.30319 folder) and select New, then DWORD. Give it the name of SchUseStrongCrypto and the Value of 1. Exit the Registry Editor, then restart your machine. 

Wednesday, February 14, 2018

SDK - Send Email Using Template with attachement

 InstantiateTemplateRequest instTemplateReq = new InstantiateTemplateRequest  
           {  
             TemplateId = templateId,  //template guid
             ObjectId = incidentId,   // template type id
             ObjectType = "incident"  
           };  
 InstantiateTemplateResponse instTemplateResp = (InstantiateTemplateResponse)service.Execute(instTemplateReq);  
 Entity instTemplate = (Entity)instTemplateResp.EntityCollection.Entities[0];  
 Guid emailGuid = service.Create(instTemplate);  
 //Add attachement  
 Entity emailAttachment = new Entity("activitymimeattachment");  
 //attachement in byte[]  
 emailAttachment["body"] = Convert.ToBase64String(attachement);  
 emailAttachment["objectid"] = new EntityReference("email", emailGuid);  
 emailAttachment["objecttypecode"] = "email";  
 emailAttachment["filename"] = item.Name;  
 service.Create(emailAttachment);  //Creates attachement to email
 SendEmailRequest sendEmailReq = new SendEmailRequest()  
           {  
             EmailId = emailGuid,  
             IssueSend = true  
           };  
  SendEmailResponse sendEmailResp = (SendEmailResponse)service.Execute(sendEmailReq);  

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));  
 }  
 }