Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
ned_blog
8 - Asteroid

I got a feature request asking for the ability to ask a question. In the end, the module in question sends an email. They want to prompt the user with a default subject line, but allow them to change it at runtime. This is not a feature that Alteryx has.

 

Again though, with a really simple VB Script, you can do a lot. There are a lot of good resources out there for scripting, in this case look here.

The other concern this user had was the temp files, since they are running on a multi-user server. There is that slim chance that 2 users will run at the same time the temp files would overwrite each other and 1 user would get the answer to the other's question. The last time I showed scripts via the run command tool, I had all the output going to standard out and then piped it to a file in the same file as the module. This obviously would not work in a multi-user environment.

 

This time I have added some simple file I/O to the VBS script that takes the prompts from a file and writes the result back to another file. I then can specify in the RunCommand properties to write the temp file to a special directory called %TEMP%. It is important to note in this case that this is the system temp directory, not the Alteryx temp directory. This means that on a shared server, every user has their own temp directory and there is no chance of 1 user getting another users answer (or question) by accident.

 

There is of course 1 more thing to worry about. What happens if someone runs this via the scheduler or API such that user interaction doesn't work? I employed a few tricks here.

 

  1. I added the command line option //T:30 to the script. That means that the script will give up waiting for the user after 30 seconds.
  2. I used the same temp file for data going to the script and data coming from the script. The default answer to the question is the 1st line of the temp file.
  3. I follow the script with a Sample tool only taking the 1st record.

Cumulatively, that means that if the user doesn't answer the question or can't because there is no user, the module gets the default answer as the result. It will of course hang for 30 seconds in the scheduler, but it won't consume any CPU during that time.

 

The module and VB script for this blog can be found at the bottom of this post. Use at your own risk. VBS scripts are definitely for advanced users and can't be supported by SRC.

 

The VBS Script:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (wscript.Arguments(0))
strDefault = objTextFile.ReadLine
strQuestion = objTextFile.ReadLine
strTitle = objTextFile.ReadLine
strIn = InputBox(strQuestion, strTitle, strDefault)
if strIn <> "" then
Set objTextFileOut = objFSO.CreateTextFile (wscript.Arguments(0))
objTextFileOut.WriteLine(strIn)
End if

 

The Configuration for the RunCommand Tool:

 

Download the files for this post here.

Comments