/ Forums / Advansys Formativ / Creating Solutions with Formativ / Create Folder and Copy Current Item

  • Creator
    Topic
  • #3932
    Declan
    Participant

    Hi – I am trying to write a script to help me organize my GroupWise Mailbox. When I have a piece of mail open, I’d like to click on a button that moves the mail to a GroupWise Folder that I use as a data store.

    I have a root folder called “People” with subfolders for individuals like “Declan Fleming”. I want the script to take the current piece of mail and copy it to People/Declan Fleming. If the folder doesn’t exist, I want the script to create the folder.

    I was able to do this with MS Outlook with this script:



    Sub movetoX()
    On Error Resume Next ‘ We’ll handle errors ourselves

    Dim destprefix As MAPIFolder
    Dim dest As MAPIFolder
    Dim item As MailItem
    Dim fname As String

    Set item = ActiveInspector.CurrentItem
    fname = item.SenderName
    Set destprefix =
    GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Folders(“People”)

    If Err.Number <> 0 Then ‘ Check to see if anything has failed yet
    MsgBox “Problem”
    Exit Sub
    End If

    Set dest = destprefix.Folders(fname)

    If Err.Number <> 0 Then ‘ An error here means the folder doesn’t exist
    Err.Clear
    destprefix.Folders.Add fname
    Set dest = destprefix.Folders(fname)
    End If

    item.Move dest

    If Err.Number <> 0 Then
    MsgBox “Problem”
    Exit Sub
    End If

    End Sub


    I’ve purchased Formativ Developer and it looks like I should be able to do this, but I’m stuck trying to create a folder, and I’m not sure the Item.Move method is valid with GW.

    Any help is appreciated greatly!

    Declan

  • Author
    Replies
  • #6633
    Support 1a
    Participant

    Yes, you can certainly do this kind of thing with Formativ. Here’s some sample code to help get you started:

    dim iMsg 
    dim iFolder
      
    '-------------------------------------------------------------------------------
    ' Main-Line processing
    '-------------------------------------------------------------------------------
    Sub Main(Client, GWEvent)
       
      on error resume next
      Set iMsg = Client.ClientState.CommandMessage
      
      if not isobject(iMsg) then
        call msgbox("Please select a message to proceed.", vbInformation, "Message Management")
        exit sub    
      end if
      
      ' Create the destination folder
      CreateFolder()
      
      ' Move the message from the current folder into the destination folder's messages collection
      call Client.ClientState.SelectedFolder.messages.move(iMsg.MessageID, iFolder.Messages)
      
      set iMsg = nothing
      set iFolder = nothing
        
    End Sub
     
     
     
    
    '-------------------------------------------------------------------------------
    ' Create the folder if not exists
    '-------------------------------------------------------------------------------
    sub CreateFolder()
       
      dim iRootFolders
     
      groupwise.account.refresh  
      set iRootFolders = groupwise.account.RootFolder.folders
      
      on error resume next
      set iFolder = iRootFolders.ItemByName("People")
          
      if iFolder is nothing then
        set iFolder = iRootFolders.add("People")
      end if
                   
      set iRootFolders = nothing  
      
    end sub
    

    I hope this helps.

    Advansys Support

    #6636
    Declan
    Participant

    Excellent, thanks for the help!

    My objective is to extract the display name of the sender of the current message and then create a People/’sender.displayname’ folder. It looks like the CreateFolder() makes the People folder, but I need a bit more help in extracting the sender display name, then creating a People/subfolder named after the display name.

    Thanks! I’m so close! 🙂

    D

    #6637
    Support 1a
    Participant

    No problems – we always like to try to assist our users. The following code may assist:

    dim iMsg 
    dim iFolder
      
    '-------------------------------------------------------------------------------
    ' Main-Line processing
    '-------------------------------------------------------------------------------
    Sub Main(Client, GWEvent)
       
      on error resume next
      Set iMsg = Client.ClientState.CommandMessage
      
      if not isobject(iMsg) then
        call msgbox("Please select a message to proceed.", vbInformation, "Message Management")
        exit sub    
      end if
      
      ' Create the destination folder
      CreateFolder(GetDisplayName(iMsg.FromText))
      
      ' Move the message from the current folder into the destination folder's messages collection
      call Client.ClientState.SelectedFolder.messages.move(iMsg.MessageID, iFolder.Messages)
      
      set iMsg = nothing
      set iFolder = nothing
        
    End Sub
     
     
     
     
    '-------------------------------------------------------------------------------
    ' Create the folder if not exists
    '-------------------------------------------------------------------------------
    sub CreateFolder(aName)
      
      if (len(aName) = 0) then
        exit sub
      end if
      
      dim iRootFolders
     
      groupwise.account.refresh  
      set iRootFolders = groupwise.account.RootFolder.folders
      
      on error resume next
      set iFolder = iRootFolders.ItemByName(aName)
          
      if iFolder is nothing then
        set iFolder = iRootFolders.add(aName)
      end if
                   
      set iRootFolders = nothing  
      
    end sub
     
     
     
    
    '-------------------------------------------------------------------------------
    ' Get the sender's display name
    '-------------------------------------------------------------------------------
    Function GetDisplayName(aName)
      
      Dim iPos
      dim iText
        
      aName = trim(aName)
      iPos = Instr(1, aName, "<", 1)
      
      if (iPos > 0) then
        iText = trim(mid(aName, 1, iPos -1))
        if (len(iText) = 0) then
          aName = mid(aName, iPos + 1)
        else
          aName = iText
        end if
      end if
      
      iPos = Instr(1, aName, ">", 1)
      if (iPos > 0) then
        aName = mid(aName, 1, iPos -1)
      end if
      
      iPos = Instr(1, aName, "@", 1)
      if (iPos > 0) then
        aName = mid(aName, 1, iPos -1)
      end if  
        
      aName = replace(aName, """", "")
      aName = replace(aName, ".", " ")
      aName = replace(aName, "/", "")
      aName = replace(aName, "", "")
      aName = replace(aName, "'", "")
      aName = replace(aName, "*", "")
      aName = replace(aName, ">", "")
      aName = replace(aName, "<", "")
                              
      GetDisplayName = trim(aName)
      
    End Function
    

    Regards,

    Advansys Support

    #6635
    Declan
    Participant

    Hi – this helps a ton!

    This is properly creating new folders in the Root with the sender names.

    The one last change I’d like it to be able to create the folders as subfolders of the People folder, which is off of the root.

    I appreciate the hand holding. Is there a reference doc I could be using that would explain these objects so I don’t drive you crazy with questions?

    Thanks!
    D

    #6634
    Support 1a
    Participant

    Try this code:

    const IDS_MAIN_FOLDER   = "People"
      
    '-------------------------------------------------------------------------------
    ' Main-Line processing
    '-------------------------------------------------------------------------------
    Sub Main(Client, GWEvent)
     
      dim iMsg 
      dim iFolder    
       
      on error resume next
      Set iMsg = Client.ClientState.CommandMessage
      
      ' Do we have a message selected?
      if not isobject(iMsg) then
        call msgbox("Please select a message to proceed.", vbInformation, "Message Management")
        exit sub    
      end if
      
      
      ' Create the destination folder
      set iFolder = CreateFolder(GetDisplayName(iMsg.FromText))
      
      
      ' Make sure we have the folder
      if iFolder is nothing then
        exit sub
      end if   
     
          
      ' Move the message from the current folder into the destination folder's messages collection
      call Client.ClientState.SelectedFolder.messages.move(iMsg.MessageID, iFolder.Messages)
      
      set iMsg = nothing
        
    End Sub
     
     
     
    '-------------------------------------------------------------------------------
    ' Create the sub folders of the People folder
    '-------------------------------------------------------------------------------
    function CreateFolder(aName)
      
      set CreateFolder = nothing   
      
      if (len(aName) = 0) then
        exit function
      end if
      
      dim iFolder   
      dim iMainFolder
      
      ' Create the main 'People' folder
      set iMainFolder = CreateMainFolder()
     
      if iMainFolder is nothing then
        exit function
      end if    
          
      ' Create the sub folders under the 'People' folder
      on error resume next
      set iFolder = iMainFolder.folders.ItemByName(aName)
          
      if iFolder is nothing then
        set iFolder = iMainFolder.folders.add(aName)
      end if
      
      set CreateFolder = iFolder
      
      set iFolder = nothing             
      set iMainFolder = nothing  
      
    end function
     
     
     
    
    '-------------------------------------------------------------------------------
    ' Create the 'people' folder which is off the root
    '-------------------------------------------------------------------------------
    function CreateMainFolder()
      
      dim iFolder
      dim iRootFolders
     
      groupwise.account.refresh  
      set iRootFolders = groupwise.account.RootFolder.folders
      
      on error resume next
      set iFolder = iRootFolders.ItemByName(IDS_MAIN_FOLDER)
          
      if iFolder is nothing then
        set iFolder = iRootFolders.add(IDS_MAIN_FOLDER)
      end if
      
      set CreateMainFolder = iFolder
      
      set iFolder = nothing             
      set iRootFolders = nothing  
      
    end function
     
     
     
    
    '-------------------------------------------------------------------------------
    ' Get the sender's display name
    '-------------------------------------------------------------------------------
    Function GetDisplayName(aName)
      
      Dim iPos
      dim iText
        
      aName = trim(aName)
      iPos = Instr(1, aName, "<", 1)
      
      if (iPos > 0) then
        iText = trim(mid(aName, 1, iPos -1))
        if (len(iText) = 0) then
          aName = mid(aName, iPos + 1)
        else
          aName = iText
        end if
      end if
      
      iPos = Instr(1, aName, ">", 1)
      if (iPos > 0) then
        aName = mid(aName, 1, iPos -1)
      end if
      
      iPos = Instr(1, aName, "@", 1)
      if (iPos > 0) then
        aName = mid(aName, 1, iPos -1)
      end if  
        
      aName = replace(aName, """", "")
      aName = replace(aName, ".", " ")
      aName = replace(aName, "/", "")
      aName = replace(aName, "", "")
      aName = replace(aName, "'", "")
      aName = replace(aName, "*", "")
      aName = replace(aName, ">", "")
      aName = replace(aName, "<", "")
                              
      GetDisplayName = trim(aName)
      
    End Function
    

    Most of these objects are native Object API. Have a look at the Novell GroupWise Object API documentation, which is linked from the drop down help menu within the Formativ development environment.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.