Monday, December 5, 2011

Add/Remove OptionSet Value at Run time Microsoft Crm 2011

Problem:
           In my post "Loop through OptionSet Using Javascript in Microsoft CRM 2011" regarding how to read all the values in the optionSet of the Microsoft Crm 2011 one of the read post question "Would you know how to remove an option from the list getOptions(), because I want the picklist to show only what needed". So in this post I will give you idea how to add remove optionSet using JavaScript.

Solution:
            For the test code I have used the account entity and from account entity I have choose "Preferred Day" and  "Preferred Time" attributes because these attribute are already added when you create only organization which for trial for 30 day. You can see the selected attributes in the Image 1.

Image 1
JavaScript code is listed in the List 1 here you can see first I have get the selected text of the Preferred Day attribute by using getText and store it in the variable which will then used in the comparison. Then in the next line  I have get the Preferred Time option set control and store it in the variable and then by using that variable get all the optionSet of the Proffered Time optionSet and store it in another variable with name "optionSets". Next I have called clearOptions function to remove all the options from the Preferred time Option set.
List 1

Next is the simple check of the Preferred Day text which user selected. I have set First option which is the Morning for the Monday , Afternoon for the Tuesday and Evening for the Wednesday , All option for the Thursday and first two option for the Friday. Here are some of the screen shots when user click the Monday there are only two option one is the empty and second is the Morning as you can see in the Image 2.
Image 2
And in Image 3 you can see the all option when user select Thursday from the Preferred Day option set.
Image 3
In above JavaScript code I have just use the addOption to add option in the option set which take the option set and the location where to add the option set in the OptionSet dropdown.
 
All and any comments / bugs / suggestions are welcomed!

Sunday, December 4, 2011

Bringing SelectedItem Into Focus Using DataGrid Control

Problem :
              When using datagrid control of the silverlight control there is situation when datagrid control has lots of records and vertical scrolling of the datagrid control is visible and the selected item of the datagrid control is not in the view as the scrolling (vertical scrolling of the datagrid is visible due to large record). So it is important to give focus to the selected item of the datagrid control.In this post I will give you solution of this problem which many of you may have face.
Solution :
               To start with how to solve above problem I have one button control with is used to bring the selected item of the datagrid control in the focus and one datagrid control which is used to show the records. The main form of the test application is shown in the Image 1 here you can see that datagrid display all the records which are assign to it ( as I have small number of records in my grid so i have reduce the height of the datagrid control so that it has vertical scrolling and the selected item is not seen when datagrid control first display). In the Image 1 you can see that selected item is not displayed which I have mention in my problem.

Image 1
The solution to above problem is quite simple but it take time when I first come across this problem. You can see the code used to bring the selected item of the datagrid control in the focus just one line of code which is used. Here I have used ScrollIntoView function of the datagrid control which take The data item (row) to scroll to as its first parameter ( here you can see that I have passed the selected item of the datagrid control) and the second parameter of the ScrollIntoView is the column of the datagrid control(the column to scroll to here I have passed the first column of the datagrid control).

List 1

The output can be seen in the Image 2, when you client the "Selected Item" button then it will focus the selected item of the datagrid control.

Image 2
Note: In the HomeViewModel which is the viewModel for the home page. I have assigned value to the Selectedcustomer before sorting the PagedCollectionView(CustomerList property) so that after sorting the selected item will disappear from the view and it should.If I assigned the first element of the PagedCollectionView (CustomerList) after sorting then first element will be selected..

If you have similar situation then you solved it by using above technique as I have done when I got similar situation.You can download the source code from here.

All and any comments / bugs / suggestions are welcomed!