From afcb0c6c6dec3c8bdcf1904762fdaadb22386a83 Mon Sep 17 00:00:00 2001 From: Jacopo Margutti Date: Sat, 19 Oct 2024 16:16:22 +0100 Subject: [PATCH] bug fix related entity --- README.md | 1 + routes/routesEspo.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 942e9a8..02ab706 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ https://kobo-connect.azurewebsites.net/kobo-to-espocrm - add a question called `skipconnect` in the Kobo form; - whenever its value is `1` (based on some condition), the submission will not be sent to EspoCRM. - If you need to **link the new record with another pre-existing record in** EspoCRM: + - ensure that the API user has read-access to the related entity; - under the header name insert the name of the Kobo question, as usual; - under the header value insert the entity name, followed by a dot (`.`), followed by the field name of type `Link` (the one containing the related entity record), followed by a dot (`.`), followed by the field name of the related entity used to relate the two. - Example headers: diff --git a/routes/routesEspo.py b/routes/routesEspo.py index 2561011..b15c10d 100644 --- a/routes/routesEspo.py +++ b/routes/routesEspo.py @@ -84,7 +84,7 @@ async def kobo_to_espocrm( multi = False repeat, repeat_no, repeat_question = False, 0, "" - related, related_entity, related_entity_field = False, "", "" + related, related_entity, linked_field, related_entity_field = False, "", "", "" # determine if kobo_field is of type multi or repeat if "multi." in kobo_field: @@ -110,7 +110,8 @@ async def kobo_to_espocrm( # else check if target_field contains a related entity and the relating field elif len(target_field.split(".")) == 3: target_entity = target_field.split(".")[0] - related_entity = target_field.split(".")[1] + linked_field = target_field.split(".")[1] + related_entity = linked_field.capitalize() related_entity_field = target_field.split(".")[2] related = True else: @@ -163,7 +164,7 @@ async def kobo_to_espocrm( update_submission_status(submission, "failed", error_message) else: kobo_value = related_records[0]["id"] - target_field = related_entity + "Id" + target_field = linked_field + "Id" # process individual field; if it's an attachment, upload it to EspoCRM kobo_value_url = str(kobo_value).replace(" ", "_")