In the example below, we have an activity in a different project and we want to copy some answers from that activity to other activities.

Below steps are the prerequisites

  1. Create an activity A and fill it with answers that you want other activities to copy.
  2. The activity can be of a different template than the one where you are copying the answers.
  3. Download the generated script from the activity A.
  4. Now download the generated script from a published template B.
  5. The idea is to copy the answers from activity A of template A to all the activities of template B.
  6. Create main.py by referring to the example below.
  7. Now your folder should contain main.py, and two generated script of A and B.
  8. Zip the folder and attach it to the template B.
  9. Now when you create activities for template B, you will have the scripts available to run from each activity.
import uuid

from kes.client import Client, Config

from generated import test_asset_table_def
from copied import test_asset_table_def as copy_asset, TestAssetRow

config = Config(
    kes_service_address='kes-table-service-training.delightfuldesert-b9ce0345.westeurope.azurecontainerapps.io:443',
    access_token='tat8QoGWT0')
client = Client(config)
activity_id = uuid.UUID('bff7a456-9242-4113-96a1-1cdb409dfca0')
activity = client.open_activity_by_id(activity_id=activity_id)
table = activity.build_table(test_asset_table_def)

table.load()
print(table[0].decimal_test_property)


config = Config()
client = Client(config)
activity_id_1 = uuid.UUID('456e70a3-0e42-4527-9f53-5ead755b7df1')
activity1 = client.open_activity_by_id()
table1 = activity1.build_table(copy_asset)

table1.load()
print(table[0].decimal_test_property)
# # Deleting row if it exists
if len(table1) > 0:
    table1.clear()

# Create a row
row = TestAssetRow(
    single_select_test_property=table[0].single_select_test_property,
    multi_select_test_property=table[0].multi_select_test_property,
    string_test_property=table[0].string_test_property,
    decimal_test_property=table[0].decimal_test_property + 1.0
)


ref = table1.append_row(row)


If you refer above example, you will see that, in the first config, I have added the access token. This is to make sure that when a user runs the script from the activity, there might be a possibility that the user doesn't have access to that particular activity.


But in the second config, I am not passing any configuration parameter, not even the activity_id. This is because the user running the script will always have access to the activity from where he is running the script. So, KES internally takes care of the authentication.


In the attachment you will see three files:

  • copied.py is the generated file for the template/acitivity where you want to copy the answers.
  • generated.py is the generated file for the activity from where you want to copy the answers.
  • main.py contains the logic to fetch values from activity A and copy it to the activity from where it is being run.