locked
Go online offline by custom code RRS feed

  • Question

  • Hi,

    We are in the process of upgrading the OS and Office from Win XP to Win 7 and Office 2003 to Office 2010 on the outlook clients. The CRM Version is 4.

    After upgrading it is seen that the Go-Online/offline is moved to "More" menu under the CRM ribbon. The client wants to see this command on the ribbon and not under the menu in the ribbon.

    We tried to see if the items of More menu can be moved on the ribbon as button directly but could not find a way. also customize ribbon did not worked as all the commands were grayed out and the orders of the buttons or menu items could not be changed

    Hence, we created a custom button on the  ribbon and than called the SDK code written under the topic "Use the Methods in the Outlook SDK Assembly" in the CRM 4.0 sdk

    The exact code is written but nothing happens the CRM is not going in offline or online mode. When the code touches the goonline/gooffline command nothing happens. CRM is freezed

    The code is copied below from the SDK. Any help on this is highly appreciated.

    using System;

    using CrmSdk;

    using Microsoft.Crm.Sdk.Utility;

    using Microsoft.Crm.Outlook.Sdk;

    namespace Microsoft.Crm.Sdk.HowTo.Outlook

    {

      public class CrmOutlookMethodsSample

      {

         public CrmOutlookMethodsSample()

         {

         }

         // NOTE:  Before running this sample, you should start the Microsoft Dynamics CRM for Outlook.

         public static bool Run(string crmServerUrl, string orgName)

         {

            bool success = true;

            try

            {

               // Set up the CRM Service.  

               CrmOutlookService outlookService = new CrmOutlookService();

               // Determine if the Outlook client is running.

               if (outlookService.IsCrmClientLoaded)

               {

                  if (outlookService.IsCrmDesktopClient)

                  {

                     // Microsoft Dynamics CRM for Outlook cannot go offline.

                     Console.WriteLine("CRM Client Desktop URL: " + outlookService.ServerUri.AbsoluteUri);

                     Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

                  }

                  else

                  {

                     // See if Microsoft Dynamics CRM for Outlook with Offline Access is offline.

                     if (outlookService.IsCrmClientOffline)

                     {

                        Console.WriteLine("CRM Client Offline URL: " + outlookService.ServerUri.AbsoluteUri);

                        Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

                        // Take Microsoft Dynamics CRM for Outlook online.

                        Console.WriteLine("Going Online...");

                        outlookService.GoOnline();

                        // Sync up with Microsoft Dynamics CRM database.

                        Console.WriteLine("Synchronizing with CRM...");

                        outlookService.Sync(OutlookSyncType.Outlook);

                        Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

                     }

                     else

                     {

                        Console.WriteLine("CRM Client Online URL: " + outlookService.ServerUri.AbsoluteUri);

                        Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

                        // Before going offline, sync up with the Microsoft Dynamics CRM database.

                        Console.WriteLine("Synchronizing with CRM...");

                        outlookService.Sync(OutlookSyncType.Outlook);

                        // Take Microsoft Dynamics CRM for Outlook offline.

                        Console.WriteLine("Going Offline...");

                        outlookService.GoOffline();

                        Console.WriteLine("CRM Client state: " + outlookService.State.ToString());

                     }

                  }

               }

            }

            catch (System.Web.Services.Protocols.SoapException)

            {

               // Perform error handling here.

               throw;

            }

            catch (Exception)

            {

               throw;

            }

            return success;

         }

      }

    }

    Thursday, October 24, 2013 6:36 AM