This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
bw:vbscript_tool [2019/03/07 11:49] runger [Appendix A – VBScript Tips] |
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: | ||
| - | * [[bw: | ||
| - | |||
| - | ====== 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 **Appendix B – VBScript Samples**. 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 **// |
| 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 26: | Line 11: | ||
| <code vb> Return “VariableName”, | <code vb> Return “VariableName”, | ||
| - | where “VariableName” is the variable that will be displayed for selection (under the F4 key) in subsequent workflow steps, and ScriptValue is the value from the VBScript statement. Note that the variable name must be enclosed in double-quotes. | + | where “VariableName” is the variable that will be displayed for selection (using the <**F4**> |
| In the example below, DataCalc is the value being “calculated” by the script. This value is then placed in a Bizweaver variable named “TimeStamp.” | In the example below, DataCalc is the value being “calculated” by the script. This value is then placed in a Bizweaver variable named “TimeStamp.” | ||
| 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. | ||
| - | {{: | + | {{ : |
| - Enter the Script text. | - Enter the Script text. | ||
| - | - See [[bw: | + | - See **//[[bw: |
| - 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 44: | Line 29: | ||
| The variables defined in a VBScript workflow step are used in subsequent steps by pressing <F4> in the field/value where they need to be used. | The variables defined in a VBScript workflow step are used in subsequent steps by pressing <F4> in the field/value where they need to be used. | ||
| </ | </ | ||
| + | |||
| ====== VBScript Tips ====== | ====== VBScript Tips ====== | ||
| + | This section includes a number of tips that may be useful when working with the VBScript tool. | ||
| ===== Special Characters in Scripts ===== | ===== Special Characters in Scripts ===== | ||
| Line 50: | 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 |
| * 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 60: | Line 47: | ||
| * Script values and variable names cannot include spaces or special characters other than an underscore (_). For example: Date Value is not acceptable, nor is Date-Value, whereas DateValue or Date_Value are acceptable. | * Script values and variable names cannot include spaces or special characters other than an underscore (_). For example: Date Value is not acceptable, nor is Date-Value, whereas DateValue or Date_Value are acceptable. | ||
| - | ====== | + | ====== VBScript Samples ====== |
| **These samples provided for reference only**. While most of them have been used in Bizweaver implementations, | **These samples provided for reference only**. While most of them have been used in Bizweaver implementations, | ||
| Line 85: | Line 72: | ||
| ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ||
| - | <code vb> | + | <code vb> |
| + | DateCalc = DatePart(" | ||
| Return " | Return " | ||
| </ | </ | ||
| ==== 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> | + | <code vb> |
| Return " | Return " | ||
| </ | </ | ||
| - | ==== Date of Prior Day ==== | ||
| + | ==== Number of current day ==== | ||
| + | <code vb> | ||
| + | Return " | ||
| + | |||
| + | |||
| + | ==== Day number of Prior Day ==== | ||
| <code vb> | <code vb> | ||
| return " | return " | ||
| </ | </ | ||
| - | ==== Day of the week (1=Sun - 7=Sat) ==== | ||
| + | ==== Day of the week (1=Sun - 7=Sat) ==== | ||
| <code vb> | <code vb> | ||
| - | Return | + | Return |
| - | ==== Day of the current month ==== | + | |
| - | <code vb>MonthDayCalc | + | ==== Number of days in current month ==== |
| - | Return "MonthDayValue", | + | <code vb> |
| - | ==== Number of the current month ==== | + | daysInMonth |
| + | Return "DaysInCurrentMonth", | ||
| + | </ | ||
| + | ==== Number of the current month ==== | ||
| <code vb> | <code vb> | ||
| Return " | Return " | ||
| - | ==== Full name of the current month ==== | ||
| + | ==== Full name of the current month ==== | ||
| <code vb> | <code vb> | ||
| Return " | Return " | ||
| - | ==== Three-character abbreviation of the current month ==== | ||
| + | ==== Three-character abbreviation of the current month ==== | ||
| <code vb> | <code vb> | ||
| Return " | Return " | ||
| - | ==== Current time in HHMMSS format, including leading zeros where necessary ==== | ||
| + | ==== Current time in HHMMSS format, including leading zeros where necessary ==== | ||
| <code vb> | <code vb> | ||
| Return " | Return " | ||
| ==== 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(" | DateCalc = DatePart(" | ||
| Line 133: | 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 " | IF " | ||
| Return " | Return " | ||
| Line 182: | Line 179: | ||
| Next | Next | ||
| Return" | Return" | ||
| + | |||
| + | ====Produce a comma-delimited list of files in a folder==== | ||
| + | <code vb> | ||
| + | ' Create comma-delimited list of files in a folder | ||
| + | Set objFSO = CreateObject(" | ||
| + | ' Change value of objFolder to the appropriate target | ||
| + | Set objFolder = objFSO.GetFolder(" | ||
| + | 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 " | ||
| + | </ | ||
| + | |||
| ==== 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=" | extension=" | ||
| Set objFSo = CreateObject(" | Set objFSo = CreateObject(" | ||
| Line 347: | Line 374: | ||
| ==== Move Files Based on Contents ==== | ==== Move Files Based on Contents ==== | ||
| - | * Unordered List ItemChange | + | * Change |
| <code vb> | <code vb> | ||
| Const ForReading = 1 | Const ForReading = 1 | ||
| Line 445: | Line 472: | ||
| Return " | Return " | ||
| </ | </ | ||
| + | |||
| + | ==== Call Bizweaver (Desktop VBScript App) ==== | ||
| + | This example shows how a VBScript file can be used as a desktop " | ||
| + | |||
| + | <code vb> | ||
| + | Const ForWriting=2 | ||
| + | ' | ||
| + | dim oFso, oFile, oShell, oShellEnv, oHomepath, parm1, parm2, oHTTP, returnValue | ||
| + | const overwrite = true | ||
| + | set oFso = CreateObject(" | ||
| + | set oShell | ||
| + | oHomepath = " | ||
| + | ' | ||
| + | parm1=InputBox(" | ||
| + | IF not isnumeric(parm1) then | ||
| + | msgbox "This value must be a number" | ||
| + | END IF | ||
| + | parm2=InputBox(" | ||
| + | IF not isnumeric(parm2) then | ||
| + | msgbox "This value must be a number" | ||
| + | END IF | ||
| + | ' | ||
| + | response=msgbox(" | ||
| + | IF isnumeric(parm1) AND isnumeric(parm2) AND response=6 then | ||
| + | strURL=" | ||
| + | ' | ||
| + | ' wscript.echo strURL | ||
| + | ' | ||
| + | Set oHTTP = CreateObject(" | ||
| + | Call oHTTP.Open(" | ||
| + | oHTTP.Send | ||
| + | ' | ||
| + | ' wscript.echo oHTTP.ResponseText | ||
| + | ' | ||
| + | IF instr(oHTTP.ResponseText,": | ||
| + | msgbox(" | ||
| + | ELSE | ||
| + | msgbox(" | ||
| + | Set oFile = oFSO.CreateTextFile (oHomepath+" | ||
| + | oFile.Write oHTTP.ResponseText | ||
| + | oFile.Close | ||
| + | END IF | ||
| + | ELSE | ||
| + | msgbox "No processing occurred" | ||
| + | END IF | ||
| + | </ | ||
| + | ==== Find and Replace seconds of a text file ==== | ||
| + | < | ||
| + | Const ForReading = 1 | ||
| + | Const ForWriting = 2 | ||
| + | Dim fs | ||
| + | Dim fname | ||
| + | Dim HasCert | ||
| + | Dim vStartNum | ||
| + | Dim vLength | ||
| + | Dim FileIndex | ||
| + | vStartNum = 1 | ||
| + | vSourcePath = " | ||
| + | vTargetPath = " | ||
| + | Set objfso = CreateObject(" | ||
| + | Set objFile = objfso.OpenTextFile(vSourcePath, | ||
| + | strtext = objFile.ReadAll | ||
| + | sSearchString1 = "< | ||
| + | sSearchString2 = "</ | ||
| + | objFile.Close | ||
| + | While InStr(vStartNum, | ||
| + | FileIndex = FileIndex + 1 | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | vLength = InStr(vStartNum, | ||
| + | strNewText = Mid(strtext, | ||
| + | Set fname = objfso.CreateTextFile(vTargetPath & " | ||
| + | fname.WriteLine strNewText | ||
| + | fname.Close | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | Wend | ||
| + | </ | ||
| + | |||
| + | ====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| | ||