Programmatically set Time Off for the System User in CRM 2011


We can make use of below sample code to set the Time Off for the user programmatically. In the below code we are setting time off of duration 8 hours on 7th May 2013.


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

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
 authCredentials.ClientCredentials.UserName.UserName = "user@domain.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["description"] = "Time Off Rule";
 calendarRule.Attributes["duration"] = 480;
 calendarRule.Attributes["extentcode"] = 2;
 calendarRule.Attributes["pattern"] = "FREQ=DAILY;INTERVAL=1;COUNT=1";
 calendarRule.Attributes["rank"] = 0;
 calendarRule.Attributes["timezonecode"] = 190;
 calendarRule.Attributes["innercalendarid"] = new EntityReference("calendar", innerCalendarId);

// starting at 12:00 on 7 May
 calendarRule.Attributes["starttime"] = new DateTime(2013, 5, 7,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 8 hours
 calendarRule1.Attributes["duration"] = 480;
 calendarRule1.Attributes["effort"] = 2.0;
 calendarRule1.Attributes["issimple"] = true;


 calendarRule1.Attributes["offset"] = 0;
 calendarRule1.Attributes["rank"] = 0;
 // subcode 6= vacation
 calendarRule1.Attributes["subcode"] = 6;
 // time code 2 = unavailable
 calendarRule1.Attributes["timecode"] = 2;
 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

Cross-domain iframe requests are blocked in Office 365 SharePoint Online.


Hi,

I was currently working on some integration tasks between SharePoint 2013 online and CRM 2011 online. Here we wanted to use one of the search pages configured in SharePoint 2013 online inside an iframe of Case form in CRM 2011 online.

SharePoint 2013 online and CRM 2011 online were part of different Office 365 domain. After specifying the url for the iframe we got the following error

Found the following kb article

http://support.microsoft.com/kb/2795602

Then tried hosting the SharePoint 2010 online search page that is part of same domain in which CRM 2011 online is. That worked properly.

Hope it helps.

Microsoft Dynamics CRM Compatibility List


Hi,

Found this article that lists the minimum version of products compatible with Microsoft Dynamics CRM 4.0 and 2011.

Do check it out

http://support.microsoft.com/kb/2669061

Bye.

 

 

JavaScript Web Resource issue in CRM 2011 after installing Update Rollup 10


Hi,

We recently installed Update Rollup 10 in our development environment and we started getting the following alert message in our JavaScript WebResource.

“You have exceeded the maximum number of 200o characters in this field; it will be truncated”

However it allows us to save the web resource properly after we close (cancel) the popup.

Check this out

http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/7f1afca5-004e-4780-9bbc-a9d6c3109c41

Bye.