0
votes

I'd like to make a call to an appointment stored in Dynamics but displayed in Outlook.

Suppose that a user opens a window with said appointment (let's say "call mom"). I've added a button to the ribbon and I'd like it to cause a gender switch upon a click. If the user hits the button, I'd like to

  1. update the appointment to be "call dad", instead, and
  2. update some fields that aren't represented in Outlook.

The first part, I think is solvable by changing the text in the open window and allowing the user to store the new, dad-friendly value the usual way - by saving while closing the frame.

However, the second part, needs to be done "under the hood", since there might be no part of Outlook client window that contains value of the corresponding field in CRM Dynamics. As far I can see, I need to create a connection directly to CRM server and write to the field there but I'm not sure how to get the GUID of that certain appointment in order to refer to it on CRM server.

EDIT:

A clarification is needed. The action described will be performed while inside the extra, open frame in Outlook for the regarded appointment. If user double clicks an appointment in the calendar, a window pops out carrying all the info about it. In that window, I need to refer to the currently opened/edited appointment and obtain its GUID for CRM reference. My apologies if it wasn't as clear "on paper" as in my head. :)

2
When the user double double clicks the appointment in the Outlook calendar, is that appointment already tracked in the CRM?Peter Majeed
@PeterMajeed What is "double double click"? Typo? However, you raise a valid point. If the OP tries to do something CRM related with an appointment that hasn't been CRM-tracked (or has been CRM-untracked, for that matter), he's going to get a null pointer exception on xxx.UserData["crmid"].Value. It's a good practice to use `if(xxx.UserData["crmid"] != null) DoTheCrmMagic();´.user1675891

2 Answers

2
votes

The unique CRM information is stored in Outlook items as custom UserProperties. If you iterate through the UserProperties for any tracked appointment, you'll find a property called crmid. Assuming you can find the appointment in interest, you can find the GUID as below:

var guid = Guid.Parse((string)appt.UserProperties["crmid"].Value);
0
votes

As a complement to the reply by @PeterMajeed one can build up the code for accessing all windows as follows.

foreach (Outlook.Inspector inspector in this.Application.Inspectors)
{
  Outlook.AppointmentItem item 
    = inspector.CurrentItem as Outlook.AppointmentItem;
  Outlook.UserProperty property = item.UserProperties["crmid"];
  String crmId = String.Empty;
  if (property != null)
    crmId = (String) item.UserProperties["crmid"].Value;
}

And if you're interested in the actual one that has triggered the event (based on the assumption that it's the active one), you can use the code below.

Outlook.Inspector inspector 
  = this.Application.ActiveInspector().CurrentItem 
    as Outlook.Inspector;