Python Scripting

Automic Automation allows you to seamlessly integrate Python code into your Automic Automation system, thus allowing you to leverage Python language to solve automation challenges.

This page includes the following:

Using Python Scripting

The Python dictionary included in the offering contains all Automic Automation variables (_automic_variables) that can be used in Python jobs. This means that you can work with Automic Automation variables using Python scripting instead of the AE scripting language. If you want to see the value of a variable to be used in your Python jobs (_automic_job), you can use the following script statement:

print(_automic_job.uc_py_jobnr)

Furthermore, you can create your own variables and use them with your Python jobs, too. To do so, use the following syntax:

_automic_job.new_variable = 'new value'

These variables - the ones provided in the Python directory, newly added or updated ones - are then published back to the Automic Automation system and displayed in the Job Report (REP), see Job Reports.

Examples

The following script statement examples allow you to:

  • Assign a value to a variable named "foo" within the Automic Automation environment.

    :set &foo# = "some value"

  • Access the "foo" variable's value directly as an attribute of the Job object in Python.

    print(_automic_job.foo)

  • Assign a value to the test_value attribute of the Job object in Python. This value will be automatically transmitted to the Automic Automation once the Python job is completed.

    _automic_job.test_value = "test01"

  • Remove the value associated with the 'foo' variable

    Note: This operation only removes the value; the "foo" key remains in the variable set.

    del_automic_job.foo

  • Iterate through all Automic Automation variables available in the Python dictionary (_automic_variables) included in the offering and print their key-value pairs:

    forkey, values in _automic_variables.items():print(f"{key} : {values}")

Registering a Variable

Use the script statement automic_register_variable to register the name and the value of a variable in the AE system. You can do so in the Process pages of Python jobs. The registered variables are stored as object variables, see Defining the Variables Page.

This is equivalent to the :REGISTER_VARIABLE script command in the AE scripting language, see :REGISTER_VARIABLE.

Syntax

automic_register_variable(Variable name, Variable value)

  • Variable name

    Name of the variable

    Format: Name of the variable without a leading ampersand (&) character. End with a hashtag (#).

  • Variable value

    Value of the relevant variable

    Format: String

Important! Variables that are registered with automic_register_variable are limited to 1023 characters. Variables that are longer are truncated to 1023 characters without notice.

Example

The following script statement allows you to register a new variable named "var_name_02" with the value "test02" in the Automic Automation system:

automic_register_variable("var_name_02", "test02")

Registering an Output File

Use the automic_register_outputfile Python script statement on the Process page of Python Jobs to register a file as an external job output. The specified file must be stored on the agent's computer on which the job is executed or must be accessible from there. It makes sense only to define files that are generated by the job. After the job has been executed, the file is listed in the Directory tab and the report dialog of the default job output. There, you can open or store the file directly via the Automic Web Interface. For more information, see Registered Job Output.

Note: Using the Output page, you can also register external files as job output. The difference lies in the registration time: The files of the Output page are registered immediately when the job is executed, regardless of whether the job could create the file. If you use this script statement, the specified file is only registered when it is called. For more information, see Registering External Output Files.

This is equivalent to the :REGISTER_OUTPUTFILE script command in the AE scripting language, see :REGISTER_OUTPUTFILE.

Syntax

automic_register_outputfile(File, User login)

Parameters

  • File

    Fully qualified path and name of the file that should be registered as a job output. Wildcard characters are not allowed. You must always specify the absolute path.

    Format: script literal

  • User login

    Defines whether the user's login data should be used

    Allowed values: Y and N

    Format: script literal

Example

The following sample script allows you to register the file C:\temp\test.txt as an output file in the Automic Automation system:

automic_register_outputfile("C:\\temp\\test.txt", "N")

The system then verifies whether the command could successfully be executed. If so, this file is registered as job output. Otherwise, the job aborts.

See also: