Problem:
Solution:
Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.
Need to read user setting so that we can use some of the user setting like time zone to display correct time for the log-in user if our portal is use MS CRM 2011 user name and password to log-in.
Solution:
To get login user setting like time format, date format, date separator, time separator, number separator and time zone code etc we need to read the "usersettings" entity. You can see the main screen of the sample application in image 1 here you can see that I have displayed all attributes of the user setting entity in data grid control. Here first I have retrieved the meta data of the user settings entity and then based on the current login user id I have retrieved the settings of the user from the MS CRM.
Image 1 |
Let me discuss code in the list List 1, here you can see that I have function “getEntityRecord“ which takes entity name as parameter and is called when the meta data request for the entity is completed and attributes are added in the collection.Here you can see that I have assigned passed entity name to the query expression object and then I just created on condition to set the system user id Guid. Here you can see that I have JavaScript to get the current login user id and then add to values of the condition. And then add that condition to the query expression object and set all columns of the query expression object to true as I want to get all the columns of the user setting entity
List 1
After the call is send and it return control is shifted to "getEntityRecord_ClickCallback" call back to process the return value from the request. Code is listed in List 2, here you can see that I have used to for each loop on the list which contains the meta data of the user setting entity.As I have retrieved record based on the current logged in user so I will get only access the entity by 0(zero) index. Here I fist check for if the entity contains attribute or not and then check the attribute type whether attribute is pick list or lookup type because to get value of the lookup and pick list is different.If you get the value of the pick list then it will give you integer part of the pick list and we need the string value of the pick list to be displayed. Here you can see that I have get the integer value of the pick list in local variable and then search for the string value of the pick list in the list ( I have also save pick list option set in local list of the record so that I don’t need to make another MS CRM call to get option sets of the particular pick list, you can also see the code of the call back of the meta data request of the user setting entity for reference).
List 2
Next is to get the value of the lookup type, for the lookup I have just convert it to entity reference type and then get the name of the lookup. In default case I have used normal way to get the value of the other type like interger, strings etc.
Note:I have also save the type of attribute in the collection so that to make the decision of pick list and lookup to get value (for reference you can see the code of the meta data call back in the sample application).
Note:I have also save the type of attribute in the collection so that to make the decision of pick list and lookup to get value (for reference you can see the code of the meta data call back in the sample application).
Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.
1 comment:
u also like this
www.bangashtemplates.blogspot.com
Post a Comment