'(Declarations)
'    Available Objects:
'        BaseObjectEngine    -  PCS Base Object Engine
'        LookupObjectEngine  -  PCS Lookup Table Engine
'        WorkflowData        -  PCS Workflow Data Engine
'        MetaObjectEngine    -  PCS Def Object Engine
'        DB                  -  PCS Database Engine
'        DataItem            -  PCS Workflow DataItem
'        ScriptInfoObject    -  PCS Workflow Script Parameter Collection
'
'End of (Declarations)

Dim mQueue
Dim mInfo
Dim Message
Dim lError

Const MQ_SEND_ACCESS = 2
Const MQ_RECEIVE_ACCESS = 1
Const MQ_PEEK_ACCESS = 32

Const MQ_DENY_NONE = 0

Const MQMSG_DELIVERY_RECOVERABLE = 1
Const MQMSG_DELIVERY_EXPRESS = 0


Public Function WorkflowScript()

'==============================================================
' On Error Resume Next is the only form of error handling in
' VBScript.  If an error is raised out of a script while it
' is running, it may cause the workflow system to slow.
' Therefore, please use On Error Resume Next in conjunction
' with the Err Object to handle any errors
' that may occur.
'==============================================================
    
    On Error Resume Next
    
    
    
    
'===============================================
' The following values are valid return codes
'-----------------------------------------------
'  0     = Success - (Default)
' -1     = Failure - Mark task as failed
' -2     = Failure - Mark task as failed and Raise WithException Flag
' -3     = Failure - Mark task as failed and Rollback workflow
'===============================================

    WorkflowScript = 0    '(Default) Success
End Function

Public Function SendMessage(ByVal QueuePath, ByVal QueueLabel, ByVal sMessage, ByVal msgLabel)

    Dim bOKSend
    
    Set mQueue = CreateObject("MSMQ.MSMQQueue")
    Set mInfo = CreateObject("MSMQ.MSMQQueueInfo")
    

    
    mInfo.PathName = QueuePath
    mInfo.Label = QueueLabel
    '==================
    ' Open the Queue
    '==================
    Set mQueue = Nothing
    On Error Resume Next
    Set mQueue = mInfo.open(MQ_SEND_ACCESS, MQ_DENY_NONE)
    bOKSend = True
    Err.Number = 0
    
    If mQueue Is Nothing Then
        '========================================
        ' Create the Queue if it doesn't exist
        '========================================
        mInfo.Create , True
        
        If Err.Number <> 0 Then
            lError = -1
            bOKSend = False
        Else
            Set mQueue = mInfo.open(MQ_SEND_ACCESS, MQ_DENY_NONE)
            If mQueue Is Nothing Then
                bOKSend = False
                lError = -1
            Else
                bOKSend = True
                lError = 0
            End If
        End If
    End If
    
    '==========================================
    ' Send the Event to the subscribed queue
    '==========================================
    
    If bOKSend Then
        Set Message = CreateObject("MSMQ.MSMQMessage")
        Message.Body = sMessage
        Message.Label = msgLabel
        Message.Delivery = MQMSG_DELIVERY_RECOVERABLE
        Message.send mQueue
    End If
    
End Function