Part 2: Increase your knowledge

In Part 2 of the tutorial you use scripting in Robots and the HighBond API to fully automate the process that you only partially automated in Part 1.

Note

You must have created the robot and the script in Part 1 before you can do Part 2.

What will I learn?

You'll learn how to:

  • use the HighBond API to interact with multiple related Diligent One objects

  • create a task and schedule a script for full process automation

Extend the script to do more

Recall that in Part 1 of the tutorial you had to manually create a collection and an analysis in Results, retrieve the unique ID of the analysis, and paste it into the code in a script editor cell.

What if you want a separate analysis for each month, and a separate collection for each year? Using the manual method, you would need to remember, in advance, to create a new analysis each month, and update the script with the new analysis ID. And once a year, you would need to remember to create a new collection.

We're going to extend the script to use the HighBond API to automatically create a new analysis each month, and a new collection each year, so that you don't need to rely on an unwieldy, error-prone manual process. We're also going to create a scheduled task to run the script automatically.

Retrieve your HighBond API token and update the password variable

Copy and paste code blocks into script editor cells

You're going to use the same method that you used in Part 1 to copy and paste code blocks into script editor cells. If it's been a while since you did Part 1, review the Guidelines.

Note

You're going to reuse the script and the cells that you already created in Part 1, and insert two additional cells. The content of some cells does not need to be updated.

  1. From the table below, copy and paste each code block into a separate cell in the script editor, when required.

    To insert a cell between two existing cells, select the first cell and click Add cell below on the script editor tool bar.

    Tip

    The most reliable way to update code in an existing cell is to click into the cell and press Ctrl+A to select all the content, and then either delete the content or paste over it.

  2. After you paste the code for a cell, and perform any specified updates in the code, click Run selected cell to see the output.

Cell descriptions and code blocks

Note

Did you retrieve your HighBond API token and update the password variable?

If you get a Python error (a red error block) at any point, see Troubleshooting.

Cell # Description and code block
Cell 1

Import required components

Cell 1 remains unchanged from Part 1 of the tutorial and you don't need to update it.

  1. Do not change anything.

  2. Run the cell.

There is no visible output when you run this cell.

Cell 2

Define the variables used in the script

Update the code in cell 2 to add additional variables required to extend the script.

Cell 3

Create a collection in Results

The code in cell 3 uses the HighBond API to find or create the Results collection with the name that you specified in the previous cell (the value of v_collection_name ).

Note

This code block represents the first key step in fully automating the process. You use Python, HCL, and the HighBond API to find or create a collection in the Results app programmatically. You have no need to open the app or interact with it manually.

Cell 4

Create an analysis in Results

The code in cell 4 uses the HighBond API to find or create the Results analysis with the name that you specified in cell 2 (the value of v_analysis_name ).

Note

This code block represents the next key step in fully automating the process. You use Python, HCL, and the HighBond API to find or create an analysis in the Results app programmatically. You have no need to open the app or interact with it manually.

The code locates the analysis in the collection you found or created in the previous cell.

Cell 5

Create a table in Results

If you have maintained the correct order of the cells, the code for finding or creating a table in Results is now in cell 5.

The code remains unchanged from Part 1 of the tutorial and you don't need to update it, except for updating the cell identifier in line 1.

  1. In line 1, update # CELL 3 to # CELL 5.

  2. Run the cell.

Note

This code block represents the final key step in fully automating the process. You use Python, HCL, and the HighBond API to find or create a table in the Results app programmatically. You have no need to open the app or interact with it manually.

The code locates the table in the analysis that you found or created in the previous cell.

Cell 6

Perform some data analysis

If you have maintained the correct order of the cells, the code for performing some sample data analysis is now in cell 6.

The code remains unchanged from Part 1 of the tutorial and you don't need to update it, except for updating the cell identifier in line 1.

  1. In line 1, update # CELL 4 to # CELL 6.

  2. Run the cell.

Cell 7

Save the output of the data analysis to the Results table

If you have maintained the correct order of the cells, the code for saving the output to Results is now in cell 7.

The code remains unchanged from Part 1 of the tutorial and you don't need to update it, except for updating the cell identifier in line 1.

  1. In line 1, update # CELL 5 to # CELL 7.

  2. Run the cell.

Check Results for the new collection, analysis, and table

Let's check the Results app to confirm that the new collection, analysis, and table were created, and that the table contains the output results from the sample data analysis.

Save the script and exit the script editor

Schedule a Robots task to run the script

So, you now have a script that fully automates a process. The script automatically finds or creates the hierarchy of objects in Results required to contain the output of the process. It also automatically creates additional hierarchy objects, as required, based on date.

However, you are running the script interactively, meaning that you have to manually run it from the script editor. The final stage in fully automating the process is to create a Robots task that automatically runs the script based on whatever schedule you specify.

What a Robots task does

A Robots task runs the script or scripts that you specify. A task provides two things critical for building automation:

  • Storage of script input The task allows you, or another user, to provide the inputs required to run the script. You provide the inputs in advance, the task stores the inputs, and then uses them each time the task runs.

  • Scheduled execution The task allows you to specify what time of day and how frequently the task will run.

Create a task

Create and schedule a task to run the script that you just created. The task requires only a single input: your HighBond API token. However, tasks can accommodate as many inputs as your script requires.

Run the task ad hoc

Even though the task is scheduled, we're going to run it ad hoc to make sure that it works.

Check the task run log file

Download and take a look at the task run log file. Because you selected Save script output to the task run log file when you committed the script, the log file contains all the script output. This record of script output can provide useful information as you start to develop script-based automation in Robots.

Check the task output over successive days

If you scheduled the task to run once a day, periodically check the output results in the Results app to make sure the task is working correctly. If the task does not run for any reason, you should get a notification sent to your email address.

Theoretically, the task will now run indefinitely, creating a new table once a day or once a month, a new analysis once a month, and a new collection once a year.

If you are using a HighBond API token with an expiry date, then the task will stop running when the token expires. You can update the task with a new, unexpired token at any time.

Disable or delete the task

Once you are satisfied that the task is running correctly based on the schedule, you can disable or delete the task.

Disable the task

Disabling the task is reversible and does not delete anything. The task is flagged as Disabled and does not run at the scheduled time, and cannot be run ad hoc.

  1. In Robots, on the Tasks tab, select the task and click > Disable.

    Result The Disabled flag appears beside the task name and the task will not run.

  2. To re-enable the task, click > Enable.

Delete the task

Deleting the task deletes only the task. It does not delete any of the associated information in the Task runs tab, and it does not delete the script.

  1. In Robots, on the Tasks tab, select the task and click > Delete.

  2. In the prompt, click Delete to confirm that you want to permanently delete the task.

What you learned

Congratulations! You've increased your understanding of using native scripting in Robots with the HighBond API.

Specifically, you have learned how to:

  • use the HighBond API to interact with multiple related Diligent One objects

  • create a task and schedule a script for full process automation

What's next?

In Part 3 of the tutorial, you will use scripting in Robots with the Python Requests library to connect to the HighBond API and to a third-party API.

Go to >  Part 3: Extend your reach

Practice interacting with Diligent One

Why not practice your new skills by creating additional robots to automate interaction with other types of Diligent One objects? Scan the Core Resources in the HighBond API Reference to see which objects you can access.

Caution

Using the API GET method ( hcl.api_get ) is safe. You are only reading data. Be careful if you use API methods to update or delete data in your organization's production Diligent One instance. Make sure that you are only interacting with test or sample data!

Without the user interface to guide you, it's easier to update or delete the wrong object.

 

Learn more

Troubleshooting

If you get a Python error (a red error block) when running a cell or the entire script, perform the troubleshooting procedure below.