Archive for December, 2016

CRM Date and Time field – Behaviors

December 18, 2016 2 comments

Recently, I was asked a question in my blog on what is the significance of the different ‘Behaviors’ of ‘Date and Time’ field.

There are 3 different behaviors available for ‘Date and Time’ field.

Date and Time field behavior

Date and Time field behavior

User Local:

  • Time zone would be applied on this behavior. Field’s Date and time would be shown based on current user’s time zone.
  • ‘User Local’ behavior of a Field can be changed to other behaviors after field creation.
  • If the field behavior changed,
    • Behavior change takes affect only to the newly added/updated field values.
    • The existing field values remain in the database in the UTC time zone format.
  • To change the behavior of the existing field values from UTC to Date Only we would need SDK call (ConvertDateAndTimeBehaviorRequest)
  • Below is the sample code

var request = new ConvertDateAndTimeBehaviorRequest(){
Attributes = new EntityAttributeCollection() {
new KeyValuePair<string, StringCollection>(“account”, new StringCollection()
{ “new_sampledatetimeattribute” })
ConversionRule = DateTimeBehaviorConversionRule.SpecificTimeZone.Value,
TimeZoneCode = 190, // Time zone code for India Standard Time (IST) in CRM
AutoConvert = false // Conversion must be done using ConversionRule

// Execute the request
var response = (ConvertDateAndTimeBehaviorResponse)_serviceProxy.Execute(request);


    • Conversion rules:
      • SpecificTimeZone: Converts UTC value to a DateOnly value as per the specified time zone code.
      • CreatedByTimeZone: Converts UTC value to a DateOnly value that the user who created the record.
      • OwnerTimeZone: Converts UTC value to a DateOnly value that the user who owns the record.
      • LastUpdatedByTimeZone: Converts UTC value to a DateOnly value that the user who last updated the record
  • When you execute the ConvertDateAndTimeBehaviorRequest message, a system job (asynchronous operation) is created to run the conversion request.

Date Only:

  • Time zone isn’t applicable to this behavior. Field values are displayed without the time zone conversion.
  • The time portion of the value is always 12:00AM
  • This Behavior can’t be changed to other behavior types, once it’s set.
  • The Date Only behavior is good for cases when information about the time of the day and the time zone isn’t required, such as such as birthdays or anniversaries.

Time-Zone Independent:

  • Time zone isn’t applicable to this behavior. The field values are displayed without the time zone conversion.
  • This Behavior can’t be changed to other behavior types, once it’s set.
  • You can use this behavior when time zone information isn’t required, such as the hotel check-in time.

Refer MSDN article for more details.


Categories: CRM Tags: , ,

Code snippet – Connect to Dynamics CRM using Organization Service C#

December 11, 2016 3 comments

Below is the sample code to connect to Dynamics 365/CRM online 2016 using simplified connection.

This sample authenticates the user with the Dynamics 365 web services by using the CrmServiceClient and methods.

Required CRM SDK .Dlls:

  • Download the SDK to get the required .dlls
Required dlls

Required dlls

Required Namespaces :

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Tooling.Connector;

Configure connection string in App.Config:

O365 Connection strings

O365 Connection strings

C# Code:

String connectionString = GetServiceConfiguration();
CrmServiceClient conn = new CrmServiceClient(connectionString);

// Uncomment below statement in case you want to use Organization Service
// IOrganizationService orgService = conn.OrganizationWebProxyClient != null ? conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

OrganizationServiceProxy orgService = conn.OrganizationServiceProxy;

// To impersonate, set the caller GUID
orgService.CallerId = new Guid(“D0DED6CA-5A65-E611-80DD-FC15B42877A8”);

// Create Account

Entity account = new Entity(“account”);
account[“name”] = “Peter Parker”;
Guid accountId = orgService.Create(account);

// Who Am I Request

// Guid userid = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;

catch (Exception ex){
Console.WriteLine(“Exception : ” + ex.Message);

// To Read Connection Strings From <App.Config>

private String GetServiceConfiguration(){
// Get available connection strings from app.config.
int count = ConfigurationManager.ConnectionStrings.Count;

// Create a filter list of connection strings so that we have a list of valid
// connection strings for Microsoft Dynamics CRM only.
List<KeyValuePair<String, String>> filteredConnectionStrings =
new List<KeyValuePair<String, String>>();

for (int a = 0; a < count; a++)
if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))
(new KeyValuePair<string, string>

// If one valid connection string is found, use that.
if (filteredConnectionStrings.Count == 1)
return filteredConnectionStrings[0].Value;

return null;

private Boolean isValidConnectionString(String connectionString){
// At a minimum, a connection string must contain one of these arguments.
if (connectionString.Contains(“Url=”) ||
connectionString.Contains(“Server=”) ||
return true;

return false;

Refer MSDN article for more details.


‘Publish Web’ option not showing up existing Azure Web Apps – Visual Studio 2015

December 7, 2016 Leave a comment

I am using VS 2015 to publish my web application to one of my Azure web apps.

But all sudden the “Publish Web” window was not listing the existing web apps.

Not listing existing web apps

Not listing existing web apps


  • Install latest Microsoft Azure SDK 2.9.6 for VS 2015 (Download)
  • You can also use ‘Microsoft Web Platform Installer’ for installation.
Install azure SDK 2.9.6

Install azure SDK 2.9.6

  • Open the VS 2015 and choose ‘Publish’ and you would get existing web apps listed.



Categories: Azure Tags: ,