Posts

Showing posts with the label C# Code

Dynamics 365 paging with fetchxml

Dynamics 365 web service has limitation to return 5000 records in a single web service call. Many a times we get the requirement to fetch more than 5000 records to meet the business requirement. Microsoft has provided the concept of paging where we can get the data returned in multiple pages. We can make use of paging and page cookie to get more then 5000 record. Below code snippet will help you achieve this. public List<Entity> GetRecordsByFetchXml(IOrganizationService service, String fetchXML)         {             List<Entity> objList = new List<Entity>();             try             {                 // Define the fetch attributes.                 // Set the number of records per page to retrieve.                 int fetchCount = 500;                 // Initialize the page number.                 int pageNumber = 1;                 // Specify the current paging cookie. For retrieving the first page,                  // pagingCookie should be null.                

Dynamics 365 Check User has Send As Privilege programatically

Business Requirement :- Many a times in our project we get the requirement to check if logged user has Send As privilege allowed in his personal setting programatically. We can use below code snippet to check the logged in user personal settings from plugin code. public bool CheckUserSendAsPrivilege(IOrganizationService service, Guid userGuid)         {             try             {                 if (userGuid != Guid.Empty)                 {                     QueryExpression queryUserSettings = new QueryExpression(UserSettings.EntityLogicalName);                     queryUserSettings.NoLock = true;                     queryUserSettings.Criteria.AddCondition(UserSettings.systemuseridAttribute, ConditionOperator.Equal, userGuid);                     queryUserSettings.ColumnSet = new ColumnSet(UserSettings.issendasallowedAttribute);                     EntityCollection ecUserSettings = null;                     ecUserSettings = service.RetrieveMultiple(queryUserSettings);            

Microsoft Dynamics CRM Publish Entities Customization using C# code PublishXmlRequest

This post is to demonstrate that you can publish entity customization with the help of C# code. In one of the project which I was working on faced the issue of publishing entity customization from web client. I was getting generic SQL error "SQL timeout error". It was very hard to publish the changes from web client and deliverable were also impacted. I searched over the internet and found that we can publish the changes using C# code without facing any issue. Sample code _serviceProxy.Execute(new PublishXmlRequest             {                 ParameterXml = @"                     <importexportxml>                         <entities>                             <entity>systemuser</entity>                             <entity>lead</entity>                         </entities>                     </importexportxml>"             }); Create Organisation service object and initialise it with