Getting CRM User Date and Time Format Setting in Silverlight Microsoft CRM 2011

If you are working with Silverlight web resource and you need to get current crm user date time format then you can query usersettings entity and get datetime format setting for user. I have used Silvercrmsaop library in my project. You can use below code for the same:

public void RetrieveUserSettingRecord(Guid _UserID)
{
try
{
this._d.BeginInvoke(delegate()
{
EntityReference EntityID = new EntityReference();
EntityID.Id = _UserID;
EntityID.LogicalName = “usersettings”;
OrganizationRequest request = new OrganizationRequest() { RequestName = “Retrieve” };
request[“Target”] = EntityID;
ColumnSet columns = new ColumnSet();
columns.Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] { “dateformatstring”, “timeformatstring” });
request[“ColumnSet”] = columns;
IOrganizationService service = SilverlightUtility.GetSoapService();
//send the async request and specify it’s callback
service.BeginExecute(request, new AsyncCallback(RetrieveCurrentUserSetting), service);

});

}
catch (Exception ex)
{
throw ex;
}

}

private void RetrieveCurrentUserSetting(IAsyncResult result)
{
try{

this._d.BeginInvoke(delegate()
{
OrganizationResponse Response = ((IOrganizationService)result.AsyncState).EndExecute(result);
SilverCrmSoap.CrmSdk.Entity _SystemUser = (SilverCrmSoap.CrmSdk.Entity)Response[“Entity”];
if (_SystemUser.GetAttributeValue<string>(“dateformatstring”) != null)
{
string DateformatString = _SystemUser.GetAttributeValue<string>(“dateformatstring”);
}
if (_SystemUser.GetAttributeValue<string>(“timeformatstring”) != null)
{
string TimeFormatString = _SystemUser.GetAttributeValue<string>(“timeformatstring”);

}
});
}
catch (Exception ex)
{
throw ex;
}

}

Hope it will help someone !!!

3 thoughts on “Getting CRM User Date and Time Format Setting in Silverlight Microsoft CRM 2011

  1. Ha

    what assembly you use for IOrganizationService.
    I can not add Microsoft.Xrm.Sdk as reference in Silverlight project

    Reply
  2. Pingback: Blog Post from the Week (7th - 13th April 2013) - The South Asia MVP Blog - Site Home - TechNet Blogs

Leave a Reply to mahenderpal Cancel reply