Sample code to update user’s calendar programmatically (work hours) in CRM 2011


Hi,

Below is the code that we can use to update user’s work hours for a specific day. Here we are setting the work hours of the user to be starting from 2 to ending at 7 p.m. for 1st of April.

IServiceManagement orgServiceManagement =
 ServiceConfigurationFactory.CreateManagement(new Uri("https://mycrm.crm5.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
 authCredentials.ClientCredentials.UserName.UserName = "username@onmicrosoft.com";
 authCredentials.ClientCredentials.UserName.Password = "password";
 AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

OrganizationServiceProxy organizationProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
 // Get the user id
 Guid userid = ((WhoAmIResponse)organizationProxy.Execute(new WhoAmIRequest())).UserId;

// Get the calendar id of the user
 Entity systemUserEntity = organizationProxy.Retrieve("systemuser", userid, new ColumnSet(new String[] { "calendarid"}));


// Retrieve the calendar of the user
 Entity userCalendarEntity = organizationProxy.Retrieve("calendar", ((Microsoft.Xrm.Sdk.EntityReference)(systemUserEntity.Attributes["calendarid"])).Id, new ColumnSet(true));

// Retrieve the calendar rules defined in the calendar
 EntityCollection calendarRules = (EntityCollection)userCalendarEntity.Attributes["calendarrules"];

// Create a new inner calendar
 Entity newInnerCalendar = new Entity("calendar");
 newInnerCalendar.Attributes["businessunitid"] = new EntityReference("businessunit", ((Microsoft.Xrm.Sdk.EntityReference)(userCalendarEntity["businessunitid"])).Id);
 Guid innerCalendarId = organizationProxy.Create(newInnerCalendar);

// Create a new calendar rule and assign the inner calendar id to it
 Entity calendarRule = new Entity("calendarrule");
 calendarRule.Attributes["duration"] = 1440;
 calendarRule.Attributes["extentcode"] = 1;
 calendarRule.Attributes["pattern"] = "FREQ=DAILY;COUNT=1";
 calendarRule.Attributes["rank"] = 0;
 calendarRule.Attributes["timezonecode"] = 190;
 calendarRule.Attributes["innercalendarid"] = new EntityReference("calendar", innerCalendarId);

// starting at 12:00 on 1 April
 calendarRule.Attributes["starttime"] = new DateTime(2013, 4, 2,0,0,0,DateTimeKind.Utc);
 calendarRules.Entities.Add(calendarRule);

// assign all the calendar rule back to the user calendar
 userCalendarEntity.Attributes["calendarrules"] = calendarRules;
 // update the user calendar entity that has the new rule
 organizationProxy.Update(userCalendarEntity);

Entity calendarRule1 = new Entity("calendarrule");

// duration of 5 hours
 calendarRule1.Attributes["duration"] = 300;
 calendarRule1.Attributes["effort"] = 1.0;
 calendarRule1.Attributes["issimple"] = true;

// offset 120 i.e. 2 hours from start time (12:00)
 calendarRule1.Attributes["offset"] = 120;
 calendarRule1.Attributes["rank"] = 0;
 calendarRule1.Attributes["subcode"] = 1;
 calendarRule1.Attributes["timecode"] = 0;
 calendarRule1.Attributes["timezonecode"] = -1;
 calendarRule1.Attributes["calendarid"] = new EntityReference("calendar", innerCalendarId);

EntityCollection innerCalendarRules = new EntityCollection();
 innerCalendarRules.EntityName = "calendarrule";
 innerCalendarRules.Entities.Add(calendarRule1);

newInnerCalendar.Attributes["calendarrules"] = innerCalendarRules;
 newInnerCalendar.Attributes["calendarid"] = innerCalendarId;
 organizationProxy.Update(newInnerCalendar);

Hope it helps.

“InsufficientMemoryException” An error has occurred issue while trying to open Organization.svc in CRM 2011.


Hi,

Got the below error while trying to open the organization.svc in browser. Although rest of the CRM was working properly.

Checked the event log and got this interesting error message over there.

Exception information:

Exception type: InsufficientMemoryException

Exception message: Memory gates checking failed because the free memory (208502784 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

at System.ServiceModel.Activation.ServiceMemoryGates.Check(Int32 minFreeMemoryPercentage, Boolean throwOnLowMemory, UInt64& availableMemoryBytes)

at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CheckMemoryCloseIdleServices(EventTraceActivity eventTraceActivity)

at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)

As suggested by the error message, increasing the RAM resolved the issue.

Bye.

Fixed – You do not have sufficient privileges to view this chart. Contact your system administrator in CRM 2011


Hi,

We might receive the below error in CRM 2011 even though the user has the System Administrator Role assigned.

We need to check that the Access Mode for the system user is set to Read-Write and not Administrative.

In case if we receive the Insufficient Permission error

Go to Admin Section of your portal and select Assign User Licenses link in it

Assign License to the user

This will resolve the issue.

Bye.

Advertisements

Object doesn’t support property or method selectNodes error in JavaScript in CRM 2011


We got the below error in one of our CRM entity form’s onload JavaScript. The same was working fine in IE9.

Similarly in Chrome and Firefox also we were getting the below error.

Finally we came to know it was because XPath is not supported in IE 10 and other browsers.

Get the more details here

http://www.w3schools.com/xpath/xpath_examples.asp

Hope it helps

New Microsoft Dynamics CRM 2011 SDK Version 5.0.14 released


The new version of SDK has been released. It can be downloaded here

http://www.microsoft.com/en-us/download/details.aspx?id=24004

List of all the significant changes made

http://msdn.microsoft.com/en-us/library/jj916625.aspx

Bye.

Entity Name specified in FetchXml does not match the entity name in the EntityExpression error in Filtered Lookup in CRM 2011.


Hi,

We had used addCustomView function to filter lookups in our email entity. However while changing the entity inside the Lookup dialog we were getting the above error.

We read in the forum that installing the Update Rollup 10 should fix the issue for the multi-entity lookup. We had Update Rollup 6 in our system and as suggested, installing UR 10 resolved the issue.

Check out the helpful link

http://social.microsoft.com/Forums/en/crmdevelopment/thread/9d3d60fb-106e-4e4c-b846-295cea4d800e

Hope it helps.