<?xml version="1.0" standalone="yes" ?><script uid="{962ACD90-276E-4382-B7E4-73DEEB9B57D7}" shared="f" desc="Add/edit a message note" help="Add or edit a note associated with a GroupWise message" imglib="groupwise.dli" imgid="178" fav="t" inten="t" vbe="f" created="20010814T152552" smod="20020220T231609" pmod="20020221T002324" lfdn="" rm="t" ver="" author="" amail="" aurl="" acom="" aphone="" comex="f" dxwrn="f"><integrations><integration type="ngw_toolbar" context="GW.MESSAGE.MAIL" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.MAIL" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_toolbar" context="GW.MESSAGE.APPOINTMENT" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_toolbar" context="GW.MESSAGE.NOTE" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_toolbar" context="GW.MESSAGE.PHONE" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_toolbar" context="GW.MESSAGE.TASK" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.APPOINTMENT" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.MAIL" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.NOTE" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.PHONE" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_contextmenu" context="GW.MESSAGE.TASK" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration><integration type="ngw_toolbar" context="GW.CLIENT.WINDOW.BROWSER" event="" seq="b" otherid="" menu="" before="" anchor="an_under"></integration></integrations><source><primary><![CDATA['-------------------------------------------------------------------------------
' Formativ Business Solutions Pack
' Add or edit message note
' Version 1.0
' 
' This applet allows you to add or edit a message note. To enable the note text to
' be stored, the applet automatically creates a message custom field called
' "Advansys Note".  This field is accessed by the applet's dialog, which allows
' you to add or edit the note text.  The applet also provides a facility to add the
' current date and time to the note (click 'Time Stamp' to add the current date
' and time). 
' 
' To view the your note text in the GroupWise client, right mouse click on the
' column headings in the message listing view, select 'More columns' from
' GroupWise and add the "Advansys Note" custom field into selected columns.
' 
' INTEGRATIONS: This applet does not require any integrations but we recommend to
' add this applet into GroupWise Toolbar or message context menu for easy access.
'
' 22 October 01 MA: Tab and some other characters [0 - 8] replaced with spaces.
' 'Delete Note' Button added to allow deletion of notes attached to the message.
' 13 February 02 GB: Updated dialog control layout
'-------------------------------------------------------------------------------
'-->Flexalock
Dim HRT
Dim Msg
Dim Fields
Dim MemoCtl
Dim MemoText
Dim IntroDlg

Const cExit = 999
Const CUSTOMFIELD = "Advansys Note"
const CAPTION = "Formativ Business Solutions"

'-------------------------------------------------------------------------------
' Mainline processing
'-------------------------------------------------------------------------------
Sub Main(Client, GWEvent)

  Dim Cmd
	Dim Field
	Dim FieldDef
	Dim FieldOut
	Dim FieldDefs
  
  HRT = Chr(13) & Chr(10) 
  
  cDone = 100
  cIntro = 102
  cCheckText = 103
  cFieldExist = 104  
  cDeleteField = 105
  cAddFieldValue = 107
	
  Cmd = cFieldExist
  
	if MessageType(Client) then
 	  
    Set Fields = Msg.Fields
    
    Do While Cmd <> cExit      
      
      ' Check the field exists
      if Cmd = cFieldExist then
        if FieldExist then
          Cmd = cIntro
        else
          Cmd = cAddCustomField
        end if
      end if
            
      'Intro Dialog
      if Cmd = cIntro then
        SetupIntroDlg
        select case IntroDlg.execute
          case Btn1 Cmd = cCheckText
            MemoText = MemoCtl.Text
          case Btn2 Cmd = cExit
          case Btn3 Cmd = cIntro
            MemoText = Date & ", " & Time & HRT & MemoCtl.Text
          case Btn4 Cmd = cDeleteField
            MemoText = MemoCtl.Text
          case else Cmd = cExit
        end select
      end if
      
      'Add Custom Field
      if Cmd = cAddCustomField then
        On Error Resume Next         
        Set FieldDefs = GroupWise.Account.FieldDefinitions      	             
      	Set FieldDef = FieldDefs.Add(CUSTOMFIELD, fgwString)          
        set FieldDefs = nothing
        set FieldDef = nothing    
        Cmd = cIntro        
      end if      
      
      ' Check the text value
      if Cmd = cCheckText then         
        if MemoText = "" then
          call msgbox("Please enter text to continue.", 64, CAPTION)
          Cmd = cIntro
        else
          Cmd = cAddFieldValue
        end if
      end if      
      
      'Add Custom field Value
      if Cmd = cAddFieldValue then
        CharacterReplace  
        On Error Resume Next   
        set Field = Fields.Add(CUSTOMFIELD, fgwString, MemoText)
        set Field = nothing
'        Call MsgBox("Notes added to this message.", 64, CAPTION)
        Cmd = cExit  
      end if    
            
      'Delete field
      if Cmd = cDeleteField then
        if DeleteNote then
          Cmd = cExit
        else
          Cmd = cIntro
        end if        
      end if
        
            
    Loop
    set Fields = nothing
  end if
  

End Sub

'-------------------------------------------------------------------------------
' Search Field name 
'-------------------------------------------------------------------------------
function FieldExist

  dim FieldObj
  dim FieldDefs
  
  On Error Resume Next     
  Set FieldDefs = GroupWise.Account.FieldDefinitions    
  set FieldObj = FieldDefs.Item(CUSTOMFIELD,fgwString)
  
  if IsObject(FieldObj)then 
    FieldExist = TRUE
  else
    FieldExist = FALSE
  end if

  'Get Field Value    
  set FieldOut = Fields.Item(CUSTOMFIELD, fgwString)
  MemoText = FieldOut.Value
  
  set FieldOut  = nothing    
  set FieldObj = nothing
  set FieldDefs = nothing
  
end function

 
'-------------------------------------------------------------------------------
' Check the the type of message
'-------------------------------------------------------------------------------
function MessageType(Client)

  On Error Resume Next   
  iCount = Client.ClientState.SelectedMessages.Count

  ' Check there is a mail item selected
	if iCount > 1 then
    MessageType = FALSE
    call msgbox("Multiple message selection is not allowed.  Please select a message to continue."&HRT&"This applet will allow you to add or edit a message note.",64,CAPTION)
    exit function
  else
    Set Msg = Client.ClientState.CommandMessage
    if IsEmpty(Msg) then
      Set Msg = GroupWise.ComposingItem
      if IsEmpty(Msg) then    
        MessageType = FALSE  
        call msgbox("Please select a message to continue."&HRT&"This applet will allow you to add or edit a message note.",64,CAPTION) 
      else    
        call msgbox("Please select a message to continue."&HRT&"This applet will allow you to add or edit a message note.",64,CAPTION)        
        MessageType = FALSE   
      end if  
    else     
      MessageType = TRUE  
    end if
  end if

end function

'-------------------------------------------------------------------------------
' Replace character
' GroupWise Bug: There is a bug in GroupWise when writing tab character inside
' custom field. This function fixed that problem by replace the tab character with
' spaces.
' This function also replace some characters which might will cause possible data
' lost with space.
'-------------------------------------------------------------------------------
function CharacterReplace

  'Replace Character
  MemoText = Replace(MemoText, Chr(9), "      ")
  MemoText = Replace(MemoText, Chr(0), " ")
  MemoText = Replace(MemoText, Chr(1), " ")
  MemoText = Replace(MemoText, Chr(2), " ")
  MemoText = Replace(MemoText, Chr(3), " ")
  MemoText = Replace(MemoText, Chr(4), " ")    
  MemoText = Replace(MemoText, Chr(5), " ")    
  MemoText = Replace(MemoText, Chr(6), " ")    
  MemoText = Replace(MemoText, Chr(7), " ")    
  MemoText = Replace(MemoText, Chr(8), " ")    
           
  
end function


'-------------------------------------------------------------------------------
' Delete note attached to this message 
'-------------------------------------------------------------------------------
function DeleteNote

  Dim Field
  Dim myVar
  
  On Error Resume Next    
  set Field = Fields.Item(CUSTOMFIELD, fgwString)
  
  if IsObject(Field) then
    if Field.Name <> "" then
      myVar = MsgBox("Are you sure you want to delete the note attached to this message?", 4, CAPTION)
      if myVar = 6 then       
        Field.Delete
        Call MsgBox("Notes removed from this message.", 64, CAPTION)
        DeleteNote = TRUE
      else
        DeleteNote = FALSE
      end if        
    else
      Call MsgBox("Unable to delete notes." & HRT &_
      "This applet found no notes attached with this message.", 64, CAPTION)
      DeleteNote = FALSE                        
    end if
  else
    Call MsgBox("Unable to delete notes." & HRT &_
    "This applet found no notes attached to this message.", 64, CAPTION)
    DeleteNote = FALSE   
  end if  
  
  set Field = nothing
       
end function

'-------------------------------------------------------------------------------
' Introduction dialog
'-------------------------------------------------------------------------------
function SetupIntroDlg
  
  dim MsgSubj
  dim FieldOut
  
  ' Message subject
  if Msg.Subject = "" then
    MsgSubj = ""
  else
    MsgSubj = " The message subject is '" & Msg.Subject & "'."
  end if
  
  set IntroDlg = Utilities.NewControlBoxDialog
  with IntroDlg
    .Caption = CAPTION
    .Title = "Add or edit a message note"
    .Button1Caption = "&Ok"
    .Button2Caption = "&Cancel"  
    .Button3Visible = TRUE 
    .Button3Caption = "&Time Stamp" 
    .Button4Visible = TRUE
    .Button4Caption = "&Delete Note"
    .AutoSize = TRUE
  end with
   
  Set PNCtl = IntroDlg.AddPanelControl 
  With PNCtl
    .Height = 25  
    .Alignment = ftaLeftJustify
    .Caption = " Subject: " & Msg.Subject    
    .Color = fclGray
    .Font.Color = fclWhite
    .Font.Style = ffsBold
    .AutoSpace = FALSE
    .SpaceBelow = 15
  End With      
      
  Set RulLbl = IntroDlg.AddMultiLineLabelControl  
  With RulLbl
    .Lines.Text = "Enter your notes in the edit window below. " &_
    "Click 'Time Stamp' to add date and time information or " &_
    "click 'Delete Note' to delete the notes from this message." 
  End With
            
  set MemoCtl = IntroDlg.AddmemoControl    
  with MemoCtl
    if MemoText = "" then
      .Caption = "Enter notes:"
    else
      .Caption = "Modify notes:"  
    end if   
    .Hint = "Add or edit a notes for this message."       
    .ScrollBars = fssVertical   
    .Text = MemoText
  end with 
  
end function
]]></primary><backup/></source></script>