Home > General > Search for CRM 2011 Appointments in Silverlight

Okay, I’m not the best Silverlight developer, I’ve only recently gotten started. And recently I was working on trying to find the appointments for a particular service. If you look at the SDK, there is a Sample: Schedule a Resource. It works great if you are creating a console application, but the same code doesn’t work if you are using Silverlight.

Here is the code from the sample that creates the AppointmentRequest:

AppointmentRequest appointmentReq = new AppointmentRequest
                    {
                        RequiredResources = new RequiredResource[] { vanReq },
                        Direction = SearchDirection.Backward,
                        Duration = 60,
                        NumberOfResults = 10,
                        ServiceId = _plumberServiceId,
                        // The search window describes the time when the resouce can be scheduled.
                        // It must be set.
                        SearchWindowStart = DateTime.Now.ToUniversalTime(),
                        SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
                        UserTimeZoneCode = 1
                    };

Now, there are a lot of fields that they didn’t set, but since they are using the DLL files, they don’t need to. The reason this same request would fail using Silverlight is because the web-service expects the arrays to not be null. Using the DLL files, they end up as just empty arrays, but since we are using the ObservableCollection in Silverlight, we have to initialize the collections by creating empty fields. Then our request will be accepted.

AppointmentRequest appointmentReq = new AppointmentRequest
                    {
                        Objectives = new ObservableCollection(),
                        RequiredResources = new ObservableCollection(),
                        AppointmentsToIgnore = new ObservableCollection(),
                        Constraints = new ObservableCollection(),
                        Sites = new ObservableCollection(),
                        // Required Fields:
                        Duration=duration,
                        Direction=SearchDirection.Forward,
                        NumberOfResults = 20
                    };

You’ll still have to set the TimeZoneCode and adjust the dates accordingly just like they do in the SDK example. My personal preference here is to retrieve the usersettings and use the timezonecode from it.

Now, for all the people out there that use my SilverCRMSoap Library I have on codeplex, I did update the source code to include a BeginExecuteSearchRequest and modified the AppointmentRequest to have the default values specified.

With that, I think my bing maps scheduler will turn out great. Once it is done, I might update this post with a screenshot.

Happy Scheduling!

– mscrmblogger

3 Responses to “Search for CRM 2011 Appointments in Silverlight”

Comments (3)
  1. Hi, Carlton, I want tot know if there is any way to filter dashboards?
    Our requirement is to show different dashboard views for different business unit users.
    Thanks for u time and patience.

  2. thanks for the post.

    it’s annoying that Microsoft is half pushing Silverlight but providing hardly any examples at all.

    I think that the objectives line should be:

    Objectives = new ObservableCollection()

    • Thanks about the missing new. I will fix that in the article.

      As far as Silverlight goes, I like Silverlight, and I like HTML5. Both are very rich and capable systems. Perhaps Scott Hanselman answered it best, "Even though browsers like Chrome release and update very often, not every company is going to upgrade all their browsers every week or even twice a year. Some enterprises will be on Firefox 3.6 for a while longer, or (hopefully not) IE6. Browser plugins like Silverlight and Flash can add new functionality faster. They are called plugins for a reason. They plug-in and add something."

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 MSCRM Blogger

This site does not necessarily represent the views of Microsoft. The material posted on this blog are provided AS-IS, and you are to use the content at your own risk. Some of the code and information on this site may use unsupported methods. If you experience any problems using the information provided through this website, please post a comment and we will do our best to assist you, however, we can in no way guarantee support or resolution.

Microsoft Dynamics®, Silverlight®, Visual Studio®, and the corresponding logos are a registered trademarks owned by Microsoft Corporation. MSCRM Blogger has made every effort to supply trademark information about company names, products, and services mentioned on this blog. All third party trademarks are the property of their respective owners. Any rights not expressly granted herein are reserved.