Using Variables in a GoAnywhere MFT Project
View some of the Frequently Asked Questions to our support staff. Included are some tips and tricks making this forum ideal for users getting started with GoAnywhere MFT. Note: Users can reply to existing topics but only our support staff can add new topics to this forum.
3 posts
Page 1 of 1
- Support Specialist
- Posts: 590
- Joined: Tue Jul 17, 2012 2:12 pm
- Location: Phoenix, AZ
-
A variable is a name associated with a value. In a GoAnywhere MFT workflow, a variable can hold a variety of values including numbers, file and folder names, IP addresses and more. You can pass in the values for variables from your applications or from other projects.
Using a Variable to override a File Name
A project outline is shown below which connects to a SFTP server and puts a file onto that server. See Figures 1 & 2.
Notice how the Source File is hard coded with the file name of C:/temp/gademo.txt. This is not flexible if your file names change regularly.
Instead of using a hard-coded value, you can use a variable in the SFTP PUT task to supply the file name. To do this, right-click on the Project Level in the Outline and select “Add a Variable.” Give the variable a name, “MyFile” and leave the initial value blank (See Figures 3 & 4).
Your project outline now has the variable MyFile added.
You now need to add this variable to the PUT task Source File field. Variable names are wrapped with ${} when they are used as an input attribute in a task (See Figure 6).
With this change, you can now run the project and pass the name of the file you want to transfer.
Passing parameters can be done several ways:
This allows you to pass a value to the variable defined earlier within the project (see Figure 8).
By filling in the File Path and Name, then clicking on the “Execute Interactively” button, you can then view the job log to see where ${MyFile} is created and set to the value “C:\Temp\GADemo2.txt.” You can also see that the file has been uploaded successfully (see Figure 9).
Figure 9
The Source for this project is located below.
Using a Variable to override a File Name
A project outline is shown below which connects to a SFTP server and puts a file onto that server. See Figures 1 & 2.
Notice how the Source File is hard coded with the file name of C:/temp/gademo.txt. This is not flexible if your file names change regularly.
Instead of using a hard-coded value, you can use a variable in the SFTP PUT task to supply the file name. To do this, right-click on the Project Level in the Outline and select “Add a Variable.” Give the variable a name, “MyFile” and leave the initial value blank (See Figures 3 & 4).
Your project outline now has the variable MyFile added.
You now need to add this variable to the PUT task Source File field. Variable names are wrapped with ${} when they are used as an input attribute in a task (See Figure 6).
With this change, you can now run the project and pass the name of the file you want to transfer.
Passing parameters can be done several ways:
- Interactively
- From another Project
- From a Monitor Job
- From a Scheduled Job
- From a GoAnywhere Services Trigger
- From an External application using the GACmd API
This allows you to pass a value to the variable defined earlier within the project (see Figure 8).
By filling in the File Path and Name, then clicking on the “Execute Interactively” button, you can then view the job log to see where ${MyFile} is created and set to the value “C:\Temp\GADemo2.txt.” You can also see that the file has been uploaded successfully (see Figure 9).
Figure 9
The Source for this project is located below.
Code: Select all
Please feel free to contact Linoma Software at [email protected] with any questions or to inquire about our Professional Services or Training programs.<project name="Using Variables - Part 2" mainModule="Main" version="2.0" logLevel="verbose">
<variable name="MyFile" value="" />
<module name="Main">
<sftp label="Connect to Server" resourceId="Test SFTP" version="1.0">
<put label="Put file on Target Server"
sourceFile="${MyFile}"
destinationDir="/Demos/inbound" />
</sftp>
</module>
<description>Basic Project with Parameter</description>
</project>
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Rick,
Can you give us an example of a multi value static variable and a For-Each loop?
Scenario: I want to get a file from 10 web servers every day for backup purposes. I want to maintain the list of of servers in a variable so that when I add a server can just update the list in the variable.
Servers: www1.example.com, www2.example.com, ww3.example.com, www4.example.com, etc.
file: /var/www/webserver.conf
Thanks!
--Brad
Can you give us an example of a multi value static variable and a For-Each loop?
Scenario: I want to get a file from 10 web servers every day for backup purposes. I want to maintain the list of of servers in a variable so that when I add a server can just update the list in the variable.
Servers: www1.example.com, www2.example.com, ww3.example.com, www4.example.com, etc.
file: /var/www/webserver.conf
Thanks!
--Brad
- Support Specialist
- Posts: 590
- Joined: Tue Jul 17, 2012 2:12 pm
- Location: Phoenix, AZ
-
Sorry Brad, just saw this.
For this process, I'm not so sure I would use a single variable to keep this list. As my grandmother used to say ... that's just "Too much sugar for a nickle".
I would use an editor and just create me a CSV file locally on the GA Server in some "Config" folder. Then, just type the names of the server in the file.
Example:
MyServers.CSV
Server1
Server2
Server3
Then save that File.
Read and loop through the CSV and apply the server name (MyData[1] during each iteration) to make the connection to and process for each iteration.
** KEEP IN MIND **
You can add additional information to the csv for processing. (From Folder, File Pattern, etc)
But, you must call "Child" project and pass it the Server Name (IP) to get this to work through your loop. GA will only interpret the 1st time through the loop, thus ... sending/processing from the 1st Server Name. Calling the 2nd project and giving it the connection information will force this to interpret each time through the loop.
You could do the same by putting the Server names into a DB Table and reading them from there as well.
Hope this helps with some options.
For this process, I'm not so sure I would use a single variable to keep this list. As my grandmother used to say ... that's just "Too much sugar for a nickle".
I would use an editor and just create me a CSV file locally on the GA Server in some "Config" folder. Then, just type the names of the server in the file.
Example:
MyServers.CSV
Server1
Server2
Server3
Then save that File.
Read and loop through the CSV and apply the server name (MyData[1] during each iteration) to make the connection to and process for each iteration.
** KEEP IN MIND **
You can add additional information to the csv for processing. (From Folder, File Pattern, etc)
But, you must call "Child" project and pass it the Server Name (IP) to get this to work through your loop. GA will only interpret the 1st time through the loop, thus ... sending/processing from the 1st Server Name. Calling the 2nd project and giving it the connection information will force this to interpret each time through the loop.
You could do the same by putting the Server names into a DB Table and reading them from there as well.
Hope this helps with some options.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
3 posts
Page 1 of 1