|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Event Scripts > Workflow > OnWorkflowStateHasChanged.LST script file |
It is called
•after the full set of documents related to the same ECO_ID has been processed by the DBWorkflow module
•after a document has been submitted to the Workflow
•at submit-to-workflow time
Through this script it is possible to know to which process/state the document has been assigned.
LST folder
Options→Environment→Workflow→
Use OnWorkflowStateHasChanged.LST script
@DOCUMENT_UNIQUE_ID |
the document unique id |
|---|---|
@ECO_ID |
the ECO_ID |
@PROCESS |
the Workflow Process name assigned to the document |
@FROM_STATE |
the state from which the process comes from |
@TO_STATE |
the state to which the process goes to |
@FROM_STATE_INDEX |
the index ( 0..N ) of the state from which the process comes from |
@TO_STATE_INDEX |
the index ( 0..N ) of the state to which the process goes to |
@SILENT |
1: if no input should be required |
@ALL_OK |
1: all the processings for the documents of the same ECO_ID were successful |
The following script is adapted for sending an email notification to all the users that have the EMAIL field not null in the DBWORKS_USERS table.
.VBSCRIPT
const temporaryZipAttachmentFileName = "C:\temp\attachment.zip"
sub main
DBWInit(TRUE)
silent = DBWInput("@SILENT")
ecoId = DBWInput("@ECO_ID")
process = DBWInput("@PROCESS")
fromState = DBWInput("@FROM_STATE")
toState = DBWInput("@TO_STATE")
docUid = DBWInput("@DOCUMENT_UNIQUE_ID")
allOk = DBWInput("@ALL_OK")
DBWShell("WorkflowGetNotesAndFileAttachment " & docUid )
if okDBW then
notes = DBWResult("@WORKFLOW_NOTES")
attachment = DBWResult("@WORKFLOW_ATTACHMENT")
else
notes = ""
attachment = ""
end if
id = DBWQueryByUid( docUid, DBWLookUp("NAME_FIELD_ID") )
user = DBWGetOption("USER_NAME")
ReDim Preserve userList(1)
okErrorMessages = 0 'to avoid messageboxes generated by shell command
DBWorkflowGetUserList toState,userList
okErrorMessages = 1
if ubound(userList) > 1 then 'users are effectively found for destination state
for j=0 to ubound(userList)-1 step 4
userId = userList(j)
fullName = userList(j+1)
phone = userList(j+2)
email = userList(j+3)
nameToAddress = userId & "@" & DBWGetOption("COMPANY_ID")
if DBWGetOption("DBWARM_USER") <> userId then
sendNotificationEmail nameToAddress,id,fromState,toState,user,attachment
end if
next
end if
end sub
sub sendNotificationEmail( nameToAddress, id, fromState, toState, user, attachment )
SUBJECT = "Workflow notification: " & id & " - state changed to """ & toState & """"
BODY_HTML01 = "<html><body>"
BODY_HTML02 = "<h1 align=""center""><FONT face=""Verdana"" size=""5"">DBWorks Workflow Notification</FONT></h1>"
BODY_HTML03 = "</br>"
BODY_HTML04 = "Document"
BODY_HTML05 = "<h0 align=""center""><FONT face=""Arial black"" size=""3"">" & id & "</FONT></h0>"
BODY_HTML06 = "</br>"
BODY_HTML07 = "has changed state from"
BODY_HTML08 = "<h0 align=""center""><FONT face=""Arial black"" size=""3"">" & fromState & "</FONT></h0>"
BODY_HTML09 = "to"
BODY_HTML10 = "<h0 align=""center""><FONT face=""Arial black"" size=""3"">" & toState & "</FONT></h0>"
BODY_HTML11 = "</br>"
BODY_HTML12 = "</br>"
BODY_HTML13 = "Sent by " & user & ", " & Date() & "</br>"
BODY_HTML14 = "</br>"
BODY_HTML15 = "</body></html>"
if attachment<>"" then
DBWShell("FileZip New " & replace(temporaryZipAttachmentFileName," ","|"))
DBWShell("FileZip Add " & replace(attachment," ","|"))
DBWShell("FileZip Create")
ATTACHMENT01 = temporaryZipAttachmentFileName
end if
DBWShell("EMail New Notification " & nameToAddress )
DBWShell("EMail Data SUBJECT " & replace(SUBJECT," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML01," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML02," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML03," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML04," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML05," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML06," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML07," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML08," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML09," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML10," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML11," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML12," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML13," ","|"))
DBWShell("EMail Data BODY_HTML " & replace(BODY_HTML14," ","|"))
DBWShell("EMail Data ATTACHMENT " & replace(ATTACHMENT01," ","|"))
DBWShell("SendEMail")
end sub