OL Learn

Custom Workflow plugin as condition


#1

Hello,

I want to create a custom Workflow plugin with the “Connect Workflow Custom Plugin Packager”. I did it successfully before, creating a simple Action plugin.

Now I want to create a Condition plugin based on VBScript but I does not work properly.

Option Explicit 
Dim PluginParams, check_file, i, OneParam, fso
'' Set Default Values for the parameters
check_file = ""

'' Get array of parameters
PluginParams = split(Script.Paramstring,"|")

'' Loop through each array element
for i = lbound(PluginParams) to ubound(PluginParams)
	if instr(PluginParams(i),"=")>0 then
		'' Found one parameter, let's split it into its own array
		OneParam = split(PluginParams(i), "=")
		'' Check whether we recognize the name, then assign the value to the proper variable
		select case OneParam(lbound(OneParam))
			case "FileNameAndPath"
				check_file = Watch.ExpandString(OneParam(ubound(OneParam)))
		end select
	end if
next
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(check_file)) Then
  Script.ReturnValue = 1
Else
  Script.ReturnValue = 0
End If

What is my mistake here? If I use the plugin in my Workflow process it always returns false. If I modify the script to run it locally with output to messagebox it works just fine. So I think the Script.ReturnValue is not correct?!

Thanks
Thomas


#2

I have found my mistake. “Watch.ExpandString()” deletes alle Backslashes in my path.

Correct code:

Option Explicit 
Dim PluginParams, check_file, i, OneParam, fso
'' Set Default Values for the parameters
check_file = ""

'' Get array of parameters
PluginParams = split(Script.Paramstring,"|")

'' Loop through each array element
for i = lbound(PluginParams) to ubound(PluginParams)
	if instr(PluginParams(i),"=")>0 then
		'' Found one parameter, let's split it into its own array
		OneParam = split(PluginParams(i), "=")
		'' Check whether we recognize the name, then assign the value to the proper variable
		select case OneParam(lbound(OneParam))
			case "FileNameAndPath"
				check_file = OneParam(ubound(OneParam))
		end select
	end if
next
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(check_file)) Then
  Script.ReturnValue = 1
Else
  Script.ReturnValue = 0
End If

#3

ExpandString() does not delete backslashes, it interprets them as signaling the start of 3-digit octal code (for instance, \101 is the equivalent of ASCII 65, which is a capital “A”). So whenever you want to use a backslash inside an ExpandString statement (or in any parseable field, for that matter), you have to escape the backslash by doubling it. So for a filename, you have to specify something like : C:\\Tests\\MyTest.pdf


#4

Thanks Phil for the detailed explanation. This significantly improves the understanding. :slightly_smiling_face: