Dynamic Variable Assignments
jdbrunkjr
![]()
- Joined: Dec 16, 2011
- Posts: 7
If a text file contained the following:
FirstName,John
LastName,Doe
FavoriteColor,Blue
How would I create job variables and assign them values as follows:
%FirstName% = "John"
%LastName% = "Doe"
%FavoriteColor% = "Blue"
My approach:
1. Use "Read Text from File" action to create %VariablesList%
2. Use "For Each" action to step through %VariablesList%
3. Use "Split Text" action to create %VariablePartsList%
4. Use "Set Variable" to create the job variable and assign its corresponding value.
My problem is that I can't figure out the syntax to use in the "Set Variable" action. I tried %%VariablesList[0]%% = %VariablesList[1]% thinking that %VariablesList[0]%, using the first row of the list, would result in "FirstName", thus leaving %FirstName% as the variable name created. The actual result was that the list row was changed to "John,John" and no variable was created.
What would the correct syntax be, or is my approach wrong?
t-hex
![]()
- Joined: Nov 13, 2011
- Posts: 152
Hope this helps :)
Job file attached:
WA Console > File > Import Job > Select *.waj file (Use it with the attached text file, or similar ones)
jdbrunkjr
![]()
- Joined: Dec 16, 2011
- Posts: 7
Nice job, t-hex!
I'm going to use a variant of your job until I figure out how to instantiate variables during runtime, if it's even possible.
My job monitors a status and state value for external processes. The actual number of combinations for a process, its status, and its state can be well over a hundred. It's not practical to try to anticipate the total number of combinations so that they can be pre-added as job variables because the number of process is too dynamic, but each one that runs saves its status and state in a specific folder for retrieval into my job.
My job loops through the different combinations of status and state for a given process and, when needed, steps through a series of things to clear the condition… thus the need for creating a variable during runtime. I'd like to create a variable (%[process][status][state]%) during runtime and set it to some value indicating the stage of its condition resolution, then delete the variable when the condition clears.
Clear as mud, right?
jdbrunkjr
![]()
- Joined: Dec 16, 2011
- Posts: 7
Nice job, t-hex!
I'm going to use a variant of your job until I figure out how to instantiate variables during runtime, if it's even possible.
My job monitors a status and state value for external processes. The actual number of combinations for a process, its status, and its state can be well over a hundred. It's not practical to try to anticipate the total number of combinations so that they can be pre-added as job variables because the number of process is too dynamic, but each one that runs saves its status and state in a specific folder for retrieval into my job.
My job loops through the different combinations of status and state for a given process and, when needed, steps through a series of things to clear the condition… thus the need for creating a variable during runtime. I'd like to create a variable (%[process][status][state]%) during runtime and set it to some value indicating the stage of its condition resolution, then delete the variable when the condition clears.
Clear as mud, right?
jdbrunkjr
![]()
- Joined: Dec 16, 2011
- Posts: 7
Oops!