'********************************************************************
'*
'* File:           AddAttachment.Vbs                                
'* Created:        April 2004                                       
'* Version:        1.0                                              
'*                                                                   
'* Main Function:  Add a new EnterpriseOne FILE/URL MO Attachment.   
'*
'* Syntax:
'* cscript.exe AddAttachment.vbs <username> <password> <environment> <GT DSTR Name> <Key> <MO Queue Name> <File Name>
'*
'* Copyright (C) 2005 Everest Software International. All Right Reserved.       
'*
'********************************************************************

ON ERROR RESUME NEXT

DIM MOW

DIM Usr
DIM Pwd
DIM Env
DIM Dsn
DIM Key
DIM Que
DIM Fil

If Wscript.Arguments.Count <> 7 Then
   Wscript.Echo "Wrong number of parameters." & vbCRLF & _
                "" & vbCRLF & _
                "Usage:" & vbCRLF & _
                "=========================" & vbCRLF & _
                "cscript.exe AddAttachment.vbs <username> <password> <environment> <GT DSTR Name>" & vbCRLF & _
                "                              <Key> <MO Queue Name> <File Name>" & vbCRLF & _
                ""
Else
   Usr = Wscript.arguments.Item(0)
   Pwd = Wscript.arguments.Item(1)
   Env = Wscript.arguments.Item(2)
   Dsn = Wscript.arguments.Item(3)
   Key = Wscript.arguments.Item(4)
   Que = Wscript.arguments.Item(5)
   Fil = Wscript.arguments.Item(6)

   Set MOW = CreateObject("OneAttachmentManager.MOWriter")

   Select Case MOW.LoginIntoEnterpriseOne(Usr, Pwd, Env)
      Case 0
         Wscript.Echo "Logged In"

         if MOW.AttachFile(Dsn, Key, Fil, Que) = 0 then
            Wscript.Echo "SUCCESS!"
         Else
            Wscript.Echo "Failed to Attach File"
         End If

         MOW.Logout
      Case 100
         Wscript.Echo "Licensing Failed"
      Case 1
         Wscript.Echo "Login Failed"
      Case 2
         Wscript.Echo "Login Crashed"
   End Select
End If

Set MOW = Nothing

