Wiki

Scale Your Enterprise

User Tools

Site Tools


bw:vbscript_tool

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bw:vbscript_tool [2019/03/07 11:54]
runger [VBScript Tool]
bw:vbscript_tool [2022/08/02 16:42] (current)
akoehler
Line 1: Line 1:
 ====== Introduction (VBScript) ====== ====== Introduction (VBScript) ======
- 
-This document describes the use of the Bizweaver VBScript tool. 
- 
-====== Audience ====== 
- 
-This document is intended for developers of Bizweaver workflows. 
- 
-====== Related Documents ====== 
- 
-The following documents contain additional information that may be helpful with the development of Bizweaver workflows. 
- 
-  * [[bw:application_introduction|Application Introduction]] 
-  * [[bw:using_variables|Using Variables]] 
- 
-====== VBScript Tool ====== 
  
 The VBScript tool is used to create “programming” statements in a Bizweaver workflow using the VBScript language. The results from a VBScript step can be used as variables in subsequent workflow steps. The VBScript tool is used to create “programming” statements in a Bizweaver workflow using the VBScript language. The results from a VBScript step can be used as variables in subsequent workflow steps.
  
-VBScript can be used for a broad range of purposes. Several VBScript samples are included in VBScript Samples section. A web search (Google, etc.) for “VBScript” and what you are trying to accomplish will typically provide a wealth of examples as well.+VBScript can be used for a broad range of purposes. Several VBScript samples are included in **//[[bw:vbscript_tool#VBScript Samples]]//** section. A web search (Google, etc.) for “VBScript” and what you are trying to accomplish will typically provide a wealth of examples as well.
  
 There are two key elements to the VBScript tool setup. First is the **VBScript statement**. This is the “program code” that gets executed. There are two key elements to the VBScript tool setup. First is the **VBScript statement**. This is the “program code” that gets executed.
Line 32: Line 17:
 A single VBScript step can contain multiple VBScript statements. There must be a “Return” statement for each VBScript statement. A single VBScript step can contain multiple VBScript statements. There must be a “Return” statement for each VBScript statement.
  
-{{:bw:vbimage1.png?384x158}}+{{  :bw:vbimage1.png?384x158  }}
  
   - Enter the Script text.   - Enter the Script text.
-      - See [[bw:vbscript_tool#vbscript_tips|VBScript Tips]] and [[bw:vbscript_tool#vbscript_samples|VBScript Samples]] for more information and sample scripts.+      - See **//[[bw:vbscript_tool#vbscript_tips|VBScript Tips]]//** and **//[[bw:vbscript_tool#vbscript_samples|VBScript Samples]]//** for more information and sample scripts.
   - Click the [**Run**] button to validate your script.   - Click the [**Run**] button to validate your script.
       - If the Return statements are not included the VBScript may execute normally but the validation will not present any results.       - If the Return statements are not included the VBScript may execute normally but the validation will not present any results.
Line 52: Line 37:
 There are three characters that have a special meaning in a VBScript. There are three characters that have a special meaning in a VBScript.
  
-  * A **single quote** is used to indicate a comment line. Keep in mind that a comment can only be one line. Comment blocks are not supported. +  * A **single quote** is used to indicate a comment line. Keep in mind that a comment can only be one line. **Comment blocks are not supported**. 
-  * An **ampersand (&)** is used to concatenate text values. This is shown in the earlier example.+  * An **ampersand (&)** is used to concatenate text values. This is shown in the earlier example image above.
   * A VBScript statement is expected to be one long string of text. This means that if you use a carriage return in the middle of the statement, the statement will fail. If you want to put line breaks in the statement, use an **underscore (_)** just before the carriage return.   * A VBScript statement is expected to be one long string of text. This means that if you use a carriage return in the middle of the statement, the statement will fail. If you want to put line breaks in the statement, use an **underscore (_)** just before the carriage return.
  
Line 87: Line 72:
 ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ====
  
-<code vb>DateCalc = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2) & "T" & right("0" & DatePart("h",Now),2) & right("0" & DatePart("n",Now),2)+<code vb> 
 +DateCalc = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2) & "T" & right("0" & DatePart("h",Now),2) & right("0" & DatePart("n",Now),2)
 Return "FileDateTime", DateCalc Return "FileDateTime", DateCalc
 </code> </code>
 ==== Text string that includes the current time. Useful for adding notes to transactions created in SBO ==== ==== Text string that includes the current time. Useful for adding notes to transactions created in SBO ====
  
-<code vb>StringCreate = "Created by Versago Bizweaver at " & CStr(Now)+<code vb>StringCreate = "Created by Bizweaver at " & CStr(Now)
 Return "CreatedByString", StringCreate Return "CreatedByString", StringCreate
 </code> </code>
-==== Date of Prior Day ==== 
  
 +==== Number of current day ====
 +<code vb>MonthDayCalc = Day(Date)
 +Return "MonthDayValue", MonthDayCalc</code>
 +
 +
 +==== Day number of Prior Day ====
 <code vb>CalcDate =(DateAdd("d",-1,Date())) <code vb>CalcDate =(DateAdd("d",-1,Date()))
 return "PriorDay",CalcDate return "PriorDay",CalcDate
 </code> </code>
-==== Day of the week (1=Sun - 7=Sat) ==== 
  
 +==== Day of the week (1=Sun - 7=Sat) ====
 <code vb>DayCalc = Weekday(Date) <code vb>DayCalc = Weekday(Date)
-Return “DayValue”, DayCalc</code> +Return "DayValue", DayCalcc</code>
-==== Day of the current month ====+
  
-<code vb>MonthDayCalc = DatePart("d",Date) +==== Number of days in current month ==== 
-Return "MonthDayValue", MonthDayCalc</code> +<code vb> 
-==== Number of the current month ====+daysInMonth = Day(DateSerial(thisYear, thisMonth + 1, 0)) 
 +Return "DaysInCurrentMonth", daysInMonth 
 +</code>
  
 +==== Number of the current month ====
 <code vb>MonthCalc = Month(now) <code vb>MonthCalc = Month(now)
 Return "MonthValue", MonthCalc</code> Return "MonthValue", MonthCalc</code>
-==== Full name of the current month ==== 
  
 +==== Full name of the current month ====
 <code vb>MonthNameCalc = MonthName(Month(now)) <code vb>MonthNameCalc = MonthName(Month(now))
 Return "MonthNameValue", MonthNameCalc</code> Return "MonthNameValue", MonthNameCalc</code>
-==== Three-character abbreviation of the current month ==== 
  
 +==== Three-character abbreviation of the current month ====
 <code vb>MonthAbbrvCalc = MonthName(Month(now),True) <code vb>MonthAbbrvCalc = MonthName(Month(now),True)
 Return "MonthAbbrvValue", MonthAbbrvCalc</code> Return "MonthAbbrvValue", MonthAbbrvCalc</code>
-==== Current time in HHMMSS format, including leading zeros where necessary ==== 
  
 +==== Current time in HHMMSS format, including leading zeros where necessary ====
 <code vb>TimeCalc = Right("0" & DatePart("h",now),2) & Right("0" & DatePart("n",now),2) & Right("0" & DatePart("s",now),2) <code vb>TimeCalc = Right("0" & DatePart("h",now),2) & Right("0" & DatePart("n",now),2) & Right("0" & DatePart("s",now),2)
 Return "TimeValue", TimeCalc</code> Return "TimeValue", TimeCalc</code>
 ==== Different dates based on day of the week.  ==== ==== Different dates based on day of the week.  ====
  
-<code vb>In this example, if the day of the week is Monday (day 2) then the current date is returned. Otherwise the date one day back is returned.+In this example, if the day of the week is Monday (day 2) then the current date is returned. Otherwise the date one day back is returned. 
 +<code vb>
 If Weekday(Date) = 2 Then If Weekday(Date) = 2 Then
 DateCalc = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2) DateCalc = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2)
Line 135: Line 129:
 ==== Test to see if current date is last day of month ==== ==== Test to see if current date is last day of month ====
  
-<code vb>Useful for controlling workflow execution based on month end.+Useful for controlling workflow execution based on month end. 
 +<code vb>
 IF "DateSerial(Year(Now), 1 + Month(Now), 0)" = "Date" THEN LastDay = "Y" ELSE LastDay = "N" END IF IF "DateSerial(Year(Now), 1 + Month(Now), 0)" = "Date" THEN LastDay = "Y" ELSE LastDay = "N" END IF
 Return "RunJob",LastDay</code> Return "RunJob",LastDay</code>
Line 184: Line 179:
 Next Next
 Return"FileCount",counter</code> Return"FileCount",counter</code>
 +
 +====Produce a comma-delimited list of files in a folder====
 +<code vb>
 +' Create comma-delimited list of files in a folder
 +Set objFSO = CreateObject("Scripting.FileSystemObject")
 +' Change value of objFolder to the appropriate target
 +Set objFolder = objFSO.GetFolder("c:\Programdata\Bizweaver\tmpFiles")
 +Set allFiles = objFolder.Files
 +dim fileList, outFile, oCount, iCount
 +'
 +If objFSO.FolderExists(objFolder) then
 +Set oFolder = objFSO.GetFolder(objFolder)
 +iCount = oFolder.files.count
 +End If
 +'
 +For Each objFile in allFiles
 + oCount = oCount + 1
 +IF oCount <> iCount Then
 +outFile = objFile
 +fileList = (fileList + outFile) + " ,"
 +End IF
 +IF oCount = iCount Then
 +outFile = objFile
 +fileList = (fileList + outFile)
 +End IF
 +Next
 +return "OutFileList", fileList
 +</code>
 +
 ==== Find the oldest file in a folder with a specific extension ==== ==== Find the oldest file in a folder with a specific extension ====
  
-<code vb>Dim extension+<code vb> 
 +Dim extension
 extension="xml" extension="xml"
 Set objFSo = CreateObject("Scripting.FileSystemObject") Set objFSo = CreateObject("Scripting.FileSystemObject")
Line 349: Line 374:
 ==== Move Files Based on Contents ==== ==== Move Files Based on Contents ====
  
-  * Unordered List ItemChange StdDestinationLocation, sInputFolder, sSearchString1 values as needed+  * Change StdDestinationLocation, sInputFolder, sSearchString1 values as needed
 <code vb> <code vb>
 Const ForReading = 1 Const ForReading = 1
Line 447: Line 472:
 Return "ErrorCount", ErrCount Return "ErrorCount", ErrCount
 </code> </code>
 +
 +==== Call Bizweaver (Desktop VBScript App) ====
 +This example shows how a VBScript file can be used as a desktop "app" to allow users to execute Bizweaver workflows as needed.
 +
 +<code vb>
 +Const ForWriting=2
 +'
 +dim oFso, oFile, oShell, oShellEnv, oHomepath, parm1, parm2, oHTTP, returnValue
 +const overwrite = true
 +set oFso      = CreateObject("Scripting.FileSystemObject")
 +set oShell    = WScript.CreateObject("WScript.Shell")
 +oHomepath = "C:"+ oshell.Environment("PROCESS").Item("HOMEPATH")
 +'
 +parm1=InputBox("Workflow ID (1=WorkflowID1, 2=WorkflowID2, 3=WorkflowID3, 4=WorkflowID4):")
 +IF not isnumeric(parm1) then
 +msgbox "This value must be a number"
 +END IF
 +parm2=InputBox("Document ID:")
 +IF not isnumeric(parm2) then
 +msgbox "This value must be a number"
 +END IF
 +'
 +response=msgbox("Continue?",vbYesNo)
 +IF isnumeric(parm1) AND isnumeric(parm2) AND response=6 then
 +strURL="https://YourBizweaverServer/BWService/api/workflow/InvokeWorkFlow?pTaskID="+parm1+"&pStartAfter=0&pArguments={vgoRecNum:"+parm2+"}"
 +'
 +' wscript.echo strURL
 +'
 +Set oHTTP = CreateObject("MSXML2.XMLHTTP") 
 +Call oHTTP.Open("GET", strURL, FALSE) 
 +oHTTP.Send
 +'
 +' wscript.echo oHTTP.ResponseText
 +'
 +IF instr(oHTTP.ResponseText,":true") > 0 then
 +msgbox("Process Successful")
 +ELSE
 +msgbox("A problem occurred")
 +Set oFile = oFSO.CreateTextFile (oHomepath+"\Desktop\Bizweaver Out.txt", ForWriting)
 +oFile.Write oHTTP.ResponseText
 +oFile.Close
 +END IF
 +ELSE
 +msgbox "No processing occurred"
 +END IF
 +</code>
 +==== Find and Replace seconds of a text file ====
 +<code>
 +Const ForReading = 1
 +Const ForWriting = 2
 +Dim fs
 +Dim fname
 +Dim HasCert
 +Dim vStartNum 
 +Dim vLength
 +Dim FileIndex 
 +vStartNum = 1
 +vSourcePath = "WorkFlow(GetCustomerFiles).Get(FileName)"
 +vTargetPath = "WorkFlow(GetCustomerFiles).Get(SourcePath)\Working\"
 +Set objfso = CreateObject("Scripting.FileSystemObject")
 +Set objFile = objfso.OpenTextFile(vSourcePath, ForReading)
 +strtext = objFile.ReadAll
 +sSearchString1 = "<customer"
 +sSearchString2 = "</customer>"
 +objFile.Close
 +While InStr(vStartNum, strtext, sSearchString1) > 0
 +    FileIndex = FileIndex + 1
 +    vStartNum = InStr(vStartNum, strtext, sSearchString1)
 +    vLength = InStr(vStartNum, strtext, sSearchString2) - InStr(vStartNum, strtext, sSearchString1) + 11
 +    strNewText = Mid(strtext, vStartNum, vLength)
 +    Set fname = objfso.CreateTextFile(vTargetPath & "WorkFlow(GetCustomerFiles).Get(FileTitleWithoutExtension)" & "_" & FileIndex & ".xml", True)
 +    fname.WriteLine strNewText
 +    fname.Close
 +    vStartNum = InStr(vStartNum, strtext, sSearchString2) + 11
 +Wend
 +</code>
 +
 +====VB Script Variables====
 +
 +^ Name           ^ Description          ^
 +|ScriptCode|The actual VBScript code that is written in the tool|
 +|StepMessage| During a failure the reason for failure will be populated here|
 +|StepStatus| True or False|
bw/vbscript_tool.1551977672.txt.gz · Last modified: 2019/03/07 11:54 by runger