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/10/07 13:02]
akoehler [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.
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.
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>
Line 108: Line 94:
 ==== 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>
  
 ==== Number of days in current month ==== ==== Number of days in current month ====
Line 133: Line 119:
 ==== 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 142: 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 191: 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 356: 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 500: Line 518:
 END IF END IF
 </code> </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.1570467743.txt.gz · Last modified: 2019/10/07 13:02 by akoehler