Automic Workload Automation

 View Only

 Automic windows job - create and inject a dynamic environment variable

Fred Shindle's profile image
Fred Shindle posted Sep 01, 2026 01:49 PM

Windows job environment variable creation and use for duration of job execution.

I have found information on how to ...but cannot seem to get the right combination of syntax and pre-process/process tab location.

Has anyone via Windows job done the following. 

  1. Dynamically create an environment variable that does NOT exist. (pre-process tab?)
  2. Set a value for that environment variable. (process tab?)
  3. Use that environment variable/value for that job execution. (process tab?)

Thanks,

Fred Shindle

Daryl Brown's profile image
Daryl Brown

It's certainly doable.  It might be easier to review what your job code is using rather than trying to troubleshoot blind, though.

but here's a simple example:

preprocess tab

:set &VARIABLE# = "Value"

process tab

echo The variable value is set to &VARIABLE#.

What kind of error / behavior are you getting?

Fred Shindle's profile image
Fred Shindle

I have used the ':set' command from both the preprocess tab and the process tab.

I am also using the echo line to display what is being passed and values are as expected.

I am trying to create an environment variable with "VariableName" and the value is a password for that variable.

What I receive is the following error that might not even be the UC4/Automic job, it could be the app not decrypting the password correctly. (checking on that).

Error:

Unhandled exception. System.ArgumentNullException: Pwd is required (Parameter 'decryptedPwd')

Daryl Brown's profile image
Daryl Brown

Hmmm....  This sounds like it has more to do with the utility you're invoking, or potentially with quoting strings in a command line...

So you're doing something like this?

preprocess tab

:set &DECRYPTED_PWD# = "Value"

process tab

utility.exe /username=user /pwd=&DECRYPTED_PWD#

Could you share your actual code here?  (I don't need to see the password itself...I'm just trying to get a sense of what commands you're invoking here to see if I notice any obvious issues with what you're doing.)

I'll throw this out there, as it's a common mistake I've seen people make..  If you're trying to do something like this in your process tab, then you will run into problems:

for /f "delims=" %%A in ('decrypt &PASSWORD#') do set decrypted_pwd=%%A
:set &DECRYPTED_PWD# = %decrypted_pwd%
echo Decrypted password = &DECRYPTED_PWD#

The reason this won't work is because UC4 generates the code -- replacing all UC4 vars with values -- before executing the process code.  You can reference vars you already defined previously in your Process tab code, but you can't interactively assign UC4 vars in the middle of a process tab.  If you're doing something like this, then you may find that the var you're trying to reference is blank, which may explain the syntax error your utility is throwing. 

Fred Shindle's profile image
Fred Shindle

I am doing the following.

The UC4 windows agent server where the environment variable previously defined was removed and the server restarted to ensure the variable was removed from the environment.

Windows job - 

  1. Windows job is defined as 'Command', with external app executable path in 'Command' window.
  2. Attributes tab is set to "Generate Task at - Runtime"

preprocess tab

:SET &ENV_VARIABLE# = "AcctName" (environment variable 'name' external application is expecting). 

:SET &ENV_VAR_VALUE# = "AcctPswd123" (environment variable 'password' external application is expecting).

process tab

@SET &ENV_VARIABLE#=&ENV_VAR_VALUE# (I have also tried this placed on the preprocess tab, same error).

echo The variable value is set to &ENV_VARIABLE#=&ENV_VAR_VALUE#.

If I execute the job without the job 'command' all the variable creates and displays (echo listings) are the correct values.

When the job is executed with the 'Command' or actual job executable I get 1 of 2 errors, 

either 

Error:

Unhandled exception. System.ArgumentNullException: Pwd is required (Parameter 'decryptedPwd')

or (after application logging changed)

Unhandled exception. System.InvalidOperationException: Missing "EnvironmentVariable" environment variable.

Daryl Brown's profile image
Daryl Brown

Ok, then my first question is: why are you using the setting of 'Interpreter Type = Command (cmd.exe)' on the Attributes tab?

It sounds like you're clearly writing a multi-line batch file here, so wouldn't 'Batch' be the appropriate choice to use here?  You already indicated it displays the script var values correctly.  (In my shop, I don't think we ever use the 'Command' setting -- we just use the 'Batch' setting as our default.)

Which actual command is throwing the error in this job?  (If you aren't specifying "@echo off" at the top of your Process tab, you should be able to see each command as it tries to execute it.)  

If you look at the JCL of the job when it fails (i.e., monitor the job), does anything jump out at you as being wrong/missing?

Fred Shindle's profile image
Fred Shindle

I am using the 'Interpreter Type - Command' because the job is a CMD job that is actually running on remove system/application.

We execute currently execute these jobs with server environment variables set, the job uses those variables during execution.  I/we are trying to define and set a value to a system environment variable on the fly or per job in essence.
The set commands I am trying to use to define the variables are on the Process/PreProcess tabs for the job to use during processing.

I only see the local UC4 logging that is giving the previously listed exception errors. (I am told the error is the same on the application side).

I suspect the 'variables' the job is setting are "Environment" in the sense of UC4, not the server level "Environment Variables".

Trying to figure that out now.

Daryl Brown's profile image
Daryl Brown

Well, I can't confidently speak to using the "command (cmd.exe)" config, as we never really use that in-house, but couldn't you configure it as a Batch job, and then just use a process tab like this?

@SET &ENV_VARIABLE#=&ENV_VAR_VALUE#

\\path\to\jobexecutable\job.exe

Pothen Verghese's profile image
Pothen Verghese

Hi Fred,

It appears you are trying to pass user-id and password as parameters to a job.

So have you tried using promptset as an option to pass the user and password. The value of password can be hidden in the prompt set. 

While using the same promptset in a Win/Unix job it can have default values or it can be dynamically updated during run time. 

Within the process tab instead of running the job directly, use the Agent Job Messenger. (https://techdocs.broadcom.com/us/en/ca-enterprise-software/intelligent-automation/automic-automation/26-0/automic-automation/Content-AWA-AdministrationPerspective-AG_Agent_JobMessenger.html#unix-and-windows )

So you may run the command as below:

&UC_JOBMD CMD="cmd_with_full_path &USR# &PWD#"

example 

&UC_JOBMD CMD="/home/oracle/bin/ChS.sh &UNME# &PSWD#"

Here &UNME# and &PSWD# are variables defined under the promptset. For passing parameters you will have to follows the syntax applicable for your command. 

Hope this is what you are looking for.

Regards

Pothen