Skip to content

Commit

Permalink
bug fix related entity
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Oct 19, 2024
1 parent 7e5f728 commit afcb0c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions routes/routesEspo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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(" ", "_")
Expand Down

0 comments on commit afcb0c6

Please sign in to comment.