Workflow function to copy a main photo between records loops

Workflow function to copy a main photo between records loops

1. We have a workflow that triggers a function each time a record in a custom module "Jobs" is edited or created.
2. Each record in Jobs has a lookup field (called "Widget") that associates a record in the Products module with the "Jobs" record.
3. The function deletes the main photo from the Jobs record.
4. The function then copies the main photo from the associated record in the Products module to the record in the Jobs module.
4. The function works, but it loops, repeatedly copying the photo again and again until the workflow is deactivated.

I can only guess that when the photo finishes uploading it triggers the workflow again.

Here is the function:

//Get the record's id and product id of the product in the lookup field
record = zoho.crm.getRecordById("Jobs",record_id);
record_related_product_id = record.get("Widget").get("id");
//Delete the job's Main Photo
response = invokeurl
[
url :"https://www.zohoapis.com.au/crm/v2/Jobs/" + record_id + "/photo"
type :DELETE
connection:"crm_oauth_connection"
];
photo = invokeurl
[
url: "https://www.zohoapis.com.au/crm/v2/Products/" + record_related_product_id + "/photo"
type: GET
connection:"crm_oauth_connection"
];
photo.setParamName("file");
response = invokeurl
[
url: "https://www.zohoapis.com.au/crm/v2/Jobs/" + record_id + "/photo"
type: POST
files: photo
connection: "crm_oauth_connection"
];