Monday, December 31, 2012

Reading Organization Setting

Problem:
               Need to read organization settings

Solution:
               To read the organization information like what is the maximum size of the file which can be uploaded? , Currency format code and currency symbol (like ($) dollar sign for USA etc), date and time format string for organization level, and fiscal year related information etc, we need to read the organization entity to get these and other organization related attributes.

Image 1

Code for the reading organization is listed in List 1, here you can see that it is simple query expression which read all the columns and no user based condition which I have added while reading the User setting (Where I have used the current user id to get the user settings).
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 organization setting entity. 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 organization setting entity for reference).
List 2
This was all how to get the organization setting to get organization setting. You can download source code and CRM 2011 solution for testing and modification from the links which are given below.
Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.


Go to Home

All and any comments / bugs / suggestions are welcomed!

Sunday, December 30, 2012

Reading User Settings by User Id

Problem:
                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).

Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.


Go to Home

All and any comments / bugs / suggestions are welcomed!

Sunday, December 16, 2012

Reading OptionSet Items Key/value Using MetaData Request

Problem:
             Sometimes we need to get the option set key value pair to display in web resource like Silverlight etc or sometimes we have option set key but we need to display value (which is the string type display in option set).

Solution:
             When creating web resource for MS CRM 2011 there are some situations when we need to display one of the option set in combo box or in dropdown html control so that user can select any of the option from the combo box or from dropdown control. In order to get option set item we need to make meta data call which can return number of item of that field of entity.You can see the screen of the sample application in Image 1; here you can see that I have continue my last post where I have display entity attribute meta data for this sample I have displayed on option set attributes and also added data grid control to display option set items.
Image 1
Let us discuss code which is used to get the option set items from by using meta data request You can see the code in List 1 you can see the function which is used to get the items "getOptionSetLabels", function will take entity schema name and also the schema name of the option set attribute and display name of the option set attribute which will be displayed while showing busy bar.
Here you can see that first property of the request is the request name is "RetreiveAttributes" and the second property which is set is logical name of the entity, and I have used entity name which is passed to the function and then is the logical name which is the schema name of the option set attribute which is also passed to the function. Both entity name and the attribute name(which is the option set ) are schema names.
List 1

Code in List 1, I have mentioned important properties of the request, now when the request return call back event handler is executed and here you can see I just get the option set meta data to loop through and get all the option set item as code is listed in List 2.
List 2

This is how you can get option set item using meta data request, if you want to get only string value of just one option set item then you can loop through the item in the option set and then use if condition to get the specific value and then break. You can use same request to get all option set item or you can get only one value of the option set item by passing the key ( integer value of the option set).

Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.


Go to Home

All and any comments / bugs / suggestions are welcomed!

Sunday, December 9, 2012

Retrieve Entity Attributes Metadata

Problem:
              Need to get information regarding entity as well entity attributes.
Solution:
              As in my last post I have explain how to get meta data of the entities in the MS Dynamic CRM 2011, and get the information such as display name, schema name , description of the entities , now in this post I will explain how to get attributes information of each of the entity by providing entity name and then display the display name, schema name ,description and other properties of the attributes which an entity has.You can see the layout in Image 1, here you can see that I have provided search box to enter name of the entity to search the attributes and then when user select entity name (as I have use auto complete box of Silverlight , I have also provide the entity names so that user can easily search name of the entity by entering some of the initial character of the entity name).Then in the data grid control I have display information of the attribute which an entity has.


Image 01

Code to retrieve entity attribute meta data is listed in List 1, here you can see some of the difference of the code which I have used in my last post to get information of the entities.First thing which different is that request name here I have used the "RetrieveEntity" as request name, and then I have also mention the Attributes in the entity filter property of the request so that we can get attributes of the entity.Here you can see that in the Entity Filter attribute of the request I have mention both entity and attribute mean I want entity meta data and also attribute meta data of the entity which I am requesting.Next attribute of the request is the "LogicalName" , here I have provided schema name of the entity which user has selected from auto complete box.
List 1

Next is to send the request to retrieve the entity and entity attribute meta data , in the call back method I just loop through the attributes to get the properties like display name, schema name, description etch of the attributes which will be displayed in the data grid control. In the call back method I have just used the proper type name for attribute type which are displayed in the entity customization.
Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.

Go to Home

All and any comments / bugs / suggestions are welcomed!