If you are looking to get current user Date and Time format you can use below code for the same
function RetrieveUserSettingRecord() {
var context;
var serverUrl;
var ODataPath;
context = Xrm.Page.context; //get context
serverUrl = context.getServerUrl();
ODataPath = serverUrl +“/XRMServices/2011/OrganizationData.svc”;
var UserID = Xrm.Page.context.getUserId(); //get current user id from context
var RetrieveUserSetting = new XMLHttpRequest();
RetrieveUserSetting.open(“GET”, ODataPath + “/UserSettingsSet(guid'” + UserID + “‘)”, true);
RetrieveUserSetting.setRequestHeader(“Accept”, “application/json”);
RetrieveUserSetting.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
RetrieveUserSetting.onreadystatechange =function() {
RetrieveUserSettingCallBack(this);
};
RetrieveUserSetting.send();
}
function RetrieveUserSettingCallBack(retrievedUserSetting) {
if (retrievedUserSetting.readyState == 4 /* complete */) {
if(retrievedUserSetting.status == 200) {
var retrievedUser = this.parent.JSON.parse(retrievedUserSetting.responseText).d;
if (retrievedUser.TimeFormatString != null)
alert(retrievedUser.TimeFormatString);
if (retrievedUser.DateFormatString != null)
alert(retrievedUser.DateFormatString);
}}
}
Enjoy !!
Hi Mahendar
Thanks for the great help.
I have tried with above code in the onload of my custom entity.
I am getting ‘Access is denied’. Any idea why I am getting this ??
you are welcome Karan,
Did you try to debug your code to see on which line you are getting this error ??
Hi Mahendar
I am getting exception “Access is denied” on the following line:
RetrieveUserSetting.open(“GET”, ODataPath + “/UserSettingsSet(guid'” + UserID + “‘)”, true);
This is strange, you should not get this error, are you able to browse UserSettingsSet directly from browser ?? using below url
http://[Your Organization Root URL]/XRMServices/2011/OrganizationData.svc/UserSettingsSet(guid’xxxxxxxxxxxxxx’) //replace guid
I tried what u said.. I am getting a Login screen asking my login credentials..
hi