Skip to content

Commit

Permalink
introduce autotype conversion for process instance variables #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvengeance committed Mar 16, 2022
1 parent 5f3e2fc commit 3cc9713
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CamundaLibrary/CamundaLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,33 +768,36 @@ def get_activity_instance(self, id: str):
return response.to_dict()

@keyword("Get Process Instance Variable", tags=['process'])
def get_process_instance_variable(self, process_instance_id: str, variable_name: str):
def get_process_instance_variable(self, process_instance_id: str, variable_name: str, auto_type_conversion: bool = True):
"""
Returns the variable with the given name from the process instance with
the given process_instance_id.
Parameters:
- ``process_instance_id``: ID of the target process instance
- ``variable_name``: name of the variable to read
- ``auto_type_conversion``: Converts JSON structures automatically in to python data structures. Default: True. When False, values are not retrieved for JSON variables, but metadata is. Only useful when you want to verify that Camunda holds certain data types.%
== Example ==
| ${variable} | Get Process Instance Variable |
| ... | process_instance_id=fcab43bc-b970-11eb-be75-0242ac110002 |
| ... | variable_name=foo |
See also:
https://docs.camunda.org/manual/7.5/reference/rest/process-instance/variables/get-single-variable/
https://docs.camunda.org/manual/latest/reference/rest/process-instance/variables/get-single-variable/
"""
with self._shared_resources.api_client as api_client:
api_instance: ProcessInstanceApi = openapi_client.ProcessInstanceApi(api_client)

try:
response = api_instance.get_process_instance_variable(
id=process_instance_id, var_name=variable_name, deserialize_value=False)
id=process_instance_id, var_name=variable_name, deserialize_value=not auto_type_conversion)
except ApiException as e:
raise ApiException(f'Failed to get variable {variable_name} from '
f'process instance {process_instance_id}:\n{e}')
return CamundaResources.convert_variable_dto(response)
if automated_type_conversion:
return CamundaResources.convert_variable_dto(response)
return response

@keyword("Evaluate Decision", tags=['decision'])
def evaluate_decision(self, key: str, variables: dict) -> list:
Expand Down
1 change: 1 addition & 0 deletions tests/robot/ExternalTask/test_dict_vars_to_json.robot
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Dictionary variable is of type JSON in camunda
${variable_instance} Get Process Instance Variable
... process_instance_id=${process_instance}[id]
... variable_name=map
... automated_type_conversion=${False}

Should Be Equal Json ${variable_instance.type} Datatype for dictionary was supposed to be Json

Expand Down

0 comments on commit 3cc9713

Please sign in to comment.