Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.
SOLVED

Passing command/arguments to Run command tool - Powershell script

Nikita-Puniani
7 - Meteor

Hi,

 

I have a windows powershell script. In command prompt, I pass filepath and filename as input parameters at run time and the script runs perfectly fine. File name is called Refresh_File.ps1. Here is the command I run 

powershell -file Refresh_File.ps1 -filepath "C:\Users\xxxxx\Documents\Output\ProcessedFile_0420.xlsx"

 

I want to pass these the highlighted arguments in alteryx at run time by using Run command tool.  This process will be promoted to the alteryx server so looking for a solution that will work in alteryx server.

 

Thanks!

Nikita

8 REPLIES 8
ScottG
Alteryx Alumni (Retired)

You can create a Batch Macro that updates the Run Command Tool with the desired file path at runtime.  Normally Batch Macros are used to repeat the same process multiple times.  However, repetition is not required.  You can send in one record and have it execute once, in other words.

 

I'll caution you regarding the file path that you have in your question.  Remember that, on Alteryx Server, the workflow will be running on the server itself, probably with a system account specified in the Server "Run As" System Settings.  So, under most circumstances, users will not have profile directories.  So C:\Users\xxxxx\Documents\ will not exist on the Server.  If I understand your use case, we mostly see that files are written out to a network file share instead, using UNC paths.

 

Attached please find a macro that does something similar with the Run Command Tool.  It moves or copies one or more files using file paths, passing the paths to either the COPY or MOVE command using Run Command.

Scott Gurney
Strategic Sales Engineer
Alteryx, Inc.
Nikita-Puniani
7 - Meteor

Thank you for the direction. I have been struggling to make this work. Yes the files will be written out to a network file share on alteryx server. I am just doing simple test of this solution on my local as poc. I am new to using macros so I have some questions.

 

1) I made an attempt using your macro. As soon i remove the input file that I am trying to dynamically pass as input I get this attached error. "when there is an outgoing connection this tool required an input file to be configured" How should i resolve this?

2) Also, do  I need to make any changes in order for the batch macro to perform this task only once?

 

Appreciate your help!

Nikita-Puniani
7 - Meteor

Hi @ScottG 

 

Can you please guide on how to configure the workflow for this macro to work? 

Note -  I just want to be able to pass a filepath of an excel file  at run time in the run command tool

 

Thanks!

 

Nikita-Puniani
7 - Meteor

Hi @ScottG 

 

 I am having difficulty comprehending many things in this macro.  It would be super helpful if you could provide me a simpler working solution that has both the macro and workflow. 

ScottG
Alteryx Alumni (Retired)

I tried to distill this down to just the basics. 

 

Attached is a workflow that has a macro that will launch Microsoft Excel, using Run Command.  The macro opens a specific Excel file by specifying the full path to the file on the command line.  In this same way, you can send in a file path to modify the behavior of the Run Command, by changing the command line argument.

 

Note that the path to Excel on my machine is C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE.  If your Excel is installed in a different path, you will have to change the Run Command Tool "Command" setting.

Scott Gurney
Strategic Sales Engineer
Alteryx, Inc.
Nikita-Puniani
7 - Meteor

Thank you @ScottG 

 

This is extremely helpful!!!  Due to an older version of alteryx unfortunately,  I am unable to import the packaged file. However I do understand and see the macro. Can you please send the screenshot of the workflow?  Assuming the workflow has the input file connected to the macro. Here is what I am seeing. If I missing seeing anything here please post picture of the workflow

 

Nikita-Puniani_0-1619456191859.png

 

Nikita-Puniani
7 - Meteor

I was able to get the results by combining the approaches in both the solutions you provided.  Thank you for the help. This was a good learning to understand how macros behave

ScottG
Alteryx Alumni (Retired)

I'm glad to hear that you got it working.  

 

For anyone else that is on an older version of Alteryx, you just have to right-click in the workflow, choose Insert, Macro, and then select the macro file (OpenExcelFile.yxmc) included in the workflow package.  

 

Temp.png

Scott Gurney
Strategic Sales Engineer
Alteryx, Inc.