/ Forums / Advansys Formativ / Creating Solutions with Formativ / Programmatically accept an appointment / Reply To: Programmatically accept an appointment

#6526
scaldwell
Participant

Here’s a brief description of what this applet is suppose to do.

We are using another applet to export our calendars from GW to .csv files, which are then uploaded to our website content management system and displayed to the public.

Each Posted Appointment (event) can have several status categories, which are assigned through the use of a custom field. The categories are Active, Canceled, Postponed, and Rescheduled. Posted appointments or events that are rescheduled are cloned, in order to preserve all event information (mainly attachments) and the startdate and status is reset. The startdate is set to the new event date and the status is set to active or “”. This is modelled of one of your sample applets.

When the new Posted Appointment is created through the clone method (which works) it is sent to the sender of it’s parent. It then must be accepted by the user. Posted Appointments don’t need to be accepted…do they? It would be cleaner if the Posted Appointment could be auto accepted by the applet. The new Posted Appointment doesn’t seem to be behaving like a true Posted Appointment.

I’ve tried this method on the new message with no luck:

 objAppt.Accept("Accept") 

Also, after the Posted Appointment is cloned it wont let me edit it again. In theory, the event can then be canceled…but whe I run the applet on this new cloned appointment and try to set the status again it says:

 Message.Object
C:Program FilesAdvansysFormativAF_EDIT_NEW.vbf
Update access is denied to current user. at line 104, column 17 

I’ve included the entire applet for your viewing pleasure…don’t laugh!! It’s my first time.

Thanks for any help you can provide.

Scott
scaldwell@ci.fayetteville.ar.us

 

'-------------------------------------------------------------------------------
' Insert your comments here
'-------------------------------------------------------------------------------

'Dialog Variables
Dim Dialog1
Dim Dialog2
Dim Dialog3
Dim PriorityCtl
Dim StatusCtl
Dim DateCtl
Dim TimeCtl
Dim MemoCtl

'Miscellaneous Variables
Dim Msg
Dim Cmd
Dim iCount
Dim Field1
Dim Field2
Dim Field3
Dim Fields
Dim FieldDefs
Dim FieldObj1
Dim FieldObj2
Dim FieldObj3
Dim sIndex1
Dim sIndex2

Const CUSTOM_FIELD1 = "STATUS"
Const CUSTOM_FIELD2 = "RESCDATE"
Const CUSTOM_FIELD3 = "RESCREASON"
Const CAPTION = "AccessFayetteville Calendar Tools"

'-------------------------------------------------------------------------------
' Main Function
'-------------------------------------------------------------------------------

Sub Main(Client, GWEvent)

  'Command Buttons
  cIntroDlg = 100
  cSelectEdit = 101
  cCheckReschedule = 102
  cReschedule = 103
  cExit = 999

  'Set the default status to 0
  sIndex1 = 1
  sIndex2 = 0

  'Set starting point
  Cmd = cIntroDlg

  Do While Cmd <> cExit
  
    If Cmd = cIntroDlg Then
      'Get the number of messages selected
      iCount = Client.ClientState.SelectedMessages.count
      If iCount > 1 Then
        MsgBox("This applet only allows single calendar events to be edited")
        Cmd = cExit
      Else
        Set Msg = Client.ClientState.CommandMessage
        AddFields
        FieldValues
        'Check message priority and pass to form
        If Msg.Priority = 1 Then
          sIndex1 = 0
        Elseif Msg.Priority = 2 Then
          sIndex1 = 1
        Elseif Msg.Priority = 3 Then
          sIndex1 = 2
        End If
        'Checks that some text is in the status field before checking for values
        If IsObject(Field1) then
          'Check custom status field for values and pass to form
          If Field1.Value = "Canceled" Then
            sIndex2 = 1
          Elseif Field1.Value = "Postponed" Then
            sIndex2 = 2
          Elseif Field1.Value = "Rescheduled" Then
            sIndex2 = 3
          Else
            sIndex2 = 0 'blank value for status signifies Active event
          End If
        End If
        
        'Create the Dialogs
        Call SetupIntroDlg(sIndex1, sIndex2)
        Select Case Dialog1.execute
          Case Btn1 Cmd = cSelectEdit
          Case Btn2 Cmd = cExit
          Case Else Cmd = cExit
        End Select     
      End If
    End If
        
    If Cmd = cSelectEdit Then
      'Update the priority field if the new priority is different from the old priority
      If (PriorityCtl.ItemIndex) <> sIndex1 Then
        Select Case PriorityCtl.ItemIndex
          Case 0 Msg.Priority = fgwLow
          Case 1 Msg.Priority = fgwNormal
          Case 2 Msg.Priority = fgwHigh
        End Select
      End If    

      'Update the status field if the new status is different from the old status
      If (StatusCtl.ItemIndex) = sIndex2 Then
        If Field1 = "Rescheduled" Then
          Cmd = cCheckReschedule
        Else
          Cmd = cExit
        End If        
      Else
        If Field1 = "" Then
          Select Case StatusCtl.ItemIndex
            Case 1 Call Fields.Add(CUSTOM_FIELD1, fgwString, "Canceled")
            Case 2 Call Fields.Add(CUSTOM_FIELD1, fgwString, "Postponed")
            Case 3 Call Fields.Add(CUSTOM_FIELD1, fgwString, "Rescheduled")
          End Select
          Cmd = cCheckReschedule        
        ElseIf Field1 = "Canceled" Then
          MsgBox("CANCELED items may not be changed")
          Cmd = cIntroDlg
        ElseIf Field1 = "Postponed" Then
          Select Case StatusCtl.ItemIndex
            Case 1 Call Fields.Add(CUSTOM_FIELD1, fgwString, "Canceled")
            Case 3 Call Fields.Add(CUSTOM_FIELD1, fgwString, "Rescheduled")
          End Select
          If StatusCtl.ItemIndex = 1 or StatusCtl.ItemIndex = 3 Then
            Cmd = cCheckReschedule
          Else
            MsgBox("POSTPONED items may only be CANCELED or RESCHEDULED")
            Cmd = cIntroDlg
          End If
        ElseIf Field1 = "Rescheduled" Then
          MsgBox("Only the explanation of a RESCHEDULED item may be changed")
          Cmd = cCheckReschedule
        End If
      End If
    End If
    
    'MsgBox(Field1)
    'MsgBox(StatusCtl.ItemIndex)
    
    If Cmd = cCheckReschedule Then
      If Field1 = "Rescheduled" Then
        Call SetupExpDlg
        Select Case Dialog3.execute
          Case Btn1 Cmd = cReschedule
          Case Btn2 Cmd = cReschedule
          Case Else Cmd = cExit
        End Select
      ElseIf StatusCtl.ItemIndex = 3 AND Field1 <> "Rescheduled" Then
        Call SetupSuppDlg
        Select Case Dialog2.execute
          Case Btn1 Cmd = cReschedule
          Case Btn2 Cmd = cReschedule
          Case Else Cmd = cExit
        End Select
      End If
    End If 
    
    If Cmd = cReschedule Then
      If (MemoCtl.Text = "") OR (MemoCtl.Text = " ") Then
        MsgBox("Explanations are REQUIRED for all rescheduled events")
        Cmd = cCheckReschedule
      Else 
        'If original is reschedule then only update the explanation
        If Field1 = "Rescheduled" Then
          Call Fields.Add(CUSTOM_FIELD3, fgwString, MemoCtl.Text)
          Cmd = cExit
        'If the new status is reschedule then add new date/time and explanation
        ElseIf (StatusCtl.ItemIndex = 3) Then
          DT = (DateCtl.Date) + (TimeCtl.Time)
            If (Msg.StartDate) = DT Then
              MsgBox("The RESCHEDULED date and time must be different from the original")
              Cmd = cCheckReschedule
            Else
              Call Fields.Add(CUSTOM_FIELD2, fgwDate, DT)
              Call Fields.Add(CUSTOM_FIELD3, fgwString, MemoCtl.Text)
              Call CreateNewEvent
              Cmd = cExit
            End If
        End If
      End If
    End If

  Loop

' Refresh view
Call GroupWise.Refresh

'Clean up variables
Set Fields = nothing
Set Field1 = nothing
'Set Field2 = nothing
Set Field3 = nothing
Set FieldObj1 = nothing
Set FieldObj2 = nothing
Set FieldObj3 = nothing
Set Dialog1 = nothing
Set Dialog2 = nothing
Set Dialog3 = nothing
Set PriorityCtl = nothing
Set StatusCtl = nothing
Set DateCtl = nothing
Set MemoCtl = nothing
Set Msg = nothing

End Sub

'-------------------------------------------------------------------------------
' Creates a new message when an event is rescheduled
'-------------------------------------------------------------------------------
function CreateNewEvent

  Dim objAppt
  Dim objNewAppt
  Dim objRecipient
  Dim NewAddress
  NewAddress = Msg.Sender
  ' Create a copy of the original Posted Appointment substituted the new date for the StartDate
  Set objAppt = Msg.Clone
  ' Set the recipient equal to the original sender which was ourself
  Set objRecipient = objAppt.Recipients.Add(NewAddress,,0)   
  With objAppt 
    '.OnCalendar = TRUE
    '.Priority = Msg.Priority
    '.FromText = "Auto Generated Event"  
    '.Place = Msg.Place
    .StartDate = (DateCtl.Date) + (TimeCtl.Time)
    '.EndDate = DT + 1      
    '.Subject = Msg.Subject
    '.BodyText.PlainText = Msg.BodyText
  End With
  
  objAppt.Accept("Accept")
  ' Get Fields of new message
  Set Fields = objAppt.Fields
  ' Set Status of new message to normal
  Call Fields.Add(CUSTOM_FIELD1, fgwString, " ")
  ' Send Message
  Set objNewAppt = objAppt.Send
  ' Clean up
  Set objRecipient = Nothing
  Set objAppt = Nothing

End function
'-------------------------------------------------------------------------------
' Adds the custom fields if they do not exist
'-------------------------------------------------------------------------------
function AddFields
   
  Set FieldDefs = GroupWise.Account.FieldDefinitions
  
  On Error Resume Next     
  Set FieldObj1 = FieldDefs.Item(CUSTOM_FIELD1, fgwString)
  Set FieldObj2 = FieldDefs.Item(CUSTOM_FIELD2, fgwDate)
  Set FieldObj3 = FieldDefs.Item(CUSTOM_FIELD3, fgwString)
  ' If the custom fields don't exist in the field definitions then add them.
  If FieldObj1 Is Nothing Then
    Call FieldDefs.Add(CUSTOM_FIELD1, fgwString) 
  Elseif FieldObj2 Is Nothing then
    Call FieldDefs.Add(CUSTOM_FIELD2, fgwDate)
  Elseif FieldObj3 Is Nothing then
    Call FieldDefs.Add(CUSTOM_FIELD3, fgwString)
  End If

  ' Refresh view
  Call GroupWise.Refresh
  
End function

'-------------------------------------------------------------------------------
' Get the values of the custom fields
'-------------------------------------------------------------------------------
function FieldValues
  
  ' Contains all field objects for the current message
  Set Fields = Msg.Fields
   
  On Error Resume Next
  ' Finds the specified field objects and there values    
  Set Field1 = Fields.Item(CUSTOM_FIELD1, fgwString)
  'Set Field2 = Fields.Item(CUSTOM_FIELD2, fgwDate)
  Set Field3 = Fields.Item(CUSTOM_FIELD3, fgwString)
  
End function

'-------------------------------------------------------------------------------
' Dialog to edit the status dialog of the event 
'-------------------------------------------------------------------------------
function SetupIntroDlg(sIndex1, sIndex2)

  Set Dialog1 = Utilities.NewControlBoxDialog
  With Dialog1
    .Height = 240
    .Caption = CAPTION    
    .Title = "Event Classification"
    .ShowWizardImage = FALSE
  End With
  
  Set PriorityCtl = Dialog1.AddRadioGroupControl
  With PriorityCtl
    .Caption = "Priority"
    .Items.Add("Low")
    .Items.Add("Normal")
    .Items.Add("High") 
    .ItemIndex = sIndex1
    .Height = 40  
    .Columns = 3
    .Hint = "Select an event priority"
  End With
  
  Set StatusCtl = Dialog1.AddRadioGroupControl
  With StatusCtl
    .Caption = "Status"
    .Items.Add("Active")
    .Items.Add("Canceled")
    .Items.Add("Postponed")
    .Items.Add("Rescheduled")  
    .ItemIndex = sIndex2
    .Height = 60  
    .Columns = 2
    .Hint = "Select an event status"
  End With

End function

'-------------------------------------------------------------------------------
' Dialog to edit reschedule information for an event 
'-------------------------------------------------------------------------------
Function SetupSuppDlg

  Set Dialog2 = Utilities.NewControlBoxDialog
  With Dialog2
    .Height = 460
    .Caption = CAPTION    
    .Title = "Reschedule Information"
    .ShowWizardImage = FALSE
  End With

  Set DateCtl = Dialog2.AddDateTimeControl
  with DateCtl
    .Caption = "Reschedule Date To:"
    .Kind = fdtkDate
    .Date = Msg.StartDate
    .MinDate = Date
    .CaptionWidth = iCaptWidth
    .CaptionAlign = ftaRightJustify
    .Hint = "Enter a new date for this event"
  end with

  Set TimeCtl = Dialog2.AddDateTimeControl
  with TimeCtl
    .Caption = "Reschedule Time To:"
    .Kind = fdtkTime
    .Time = Msg.StartDate
    .CaptionWidth = iCaptWidth
    .CaptionAlign = ftaRightJustify
    .Hint = "Enter a new time for this event"
  end with
  
  Set MemoCtl = Dialog2.AddMemoControl
  with MemoCtl
    .Caption = "I am rescheduling this event because:"
    .ScrollBars = 4
    .Text = field3
    .CaptionAlign = ftaRightJustify
    .WordWrap = TRUE
    .hint = "Enter an explanation for this reschedule"
  end with 

end Function

'-------------------------------------------------------------------------------
' Dialog to edit reschedule explanation 
'-------------------------------------------------------------------------------
Function SetupExpDlg

  Set Dialog3 = Utilities.NewControlBoxDialog
  With Dialog3
    .Height = 425
    .Caption = CAPTION    
    .Title = "Reschedule Information"
    .ShowWizardImage = FALSE
  End With
    
  Set MemoCtl = Dialog3.AddMemoControl
  with MemoCtl
    .Caption = "Edit Explanation:"
    .ScrollBars = 4
    .Text = field3
    .CaptionAlign = ftaRightJustify
    .WordWrap = TRUE
    .hint = "Enter an explanation for this reschedule"
  end with 

end Function