How to Transfer File Upload Data from Zoho Creator to Zoho CRM's Attachment Section

Sync Image,File upload field data from Creator to CRM Attachment

Overview

In job management, tracking documents and attachments can be cumbersome. Zoho Creator provides automation tools to make this process seamless. This guide walks you through a Deluge script to streamline job image handling between Zoho Creator and Zoho CRM, with optional integration into ZohoWorkDrive.

Scenario

Suppose you have two forms in Zoho Creator:

1.Add Job Form: This receives data from the CRM "Job Module," including a unique CRM ID.
2.Comment on Job Scheduler Form: Here, users upload images and comments about the job. A subform, Upload_Attachments, allows users to upload job-related images. These images are then synced to the Zoho CRM attachment section from Creator.


Objective

Ensure that each image uploaded through the Comment on Job Scheduler Form is:

1.Checked to avoid duplicate uploads in Zoho CRM.
2.Downloaded from Zoho Creator and attached to the CRM record if not already present.
3.Optionally uploaded to Zoho WorkDrive for centralized file management.


Here's the Deluge script to automate this process:

// Fetch the CRM record based on the CRM ID from Zoho Creator get_crm_record = zoho.crm.getRecordById("Install", input.Job_Name1.Crm_ID.toLong()); // Retrieve existing attachments in CRM for this job Attach = zoho.crm.getRelatedRecords("Attachments", "Install", input.Job_Name1.Crm_ID.toLong()); // Initialize flag to check for duplicate images flag = 0; for each rec in Upload_Attachments { // Get the file name from the uploaded image var = ifnull(rec.Image.getSuffix("image/").getPrefix("\""), ""); // Check if the image is not empty if (rec.Image != null) { // Check if the image already exists in CRM attachments for each rec in Attach { if (var == rec.get("File_Name")) { flag = 1; } } // If the image doesn't exist in CRM, download it and attach it if (flag == 0) { file = invokeurl [ url :"https://creator.zoho.com/api/v2/marco.herbst/prototype/report/Comments_for_Job_Report/" + input.ID + "/Upload_Attachments.Image/" + rec.ID + "/download" type :GET connection:"zcreator" ]; Attach_file = zoho.crm.attachFile("Install", input.Job_Name1.Crm_ID.toLong(), file); } // Get the folder ID from CRM to upload the file to WorkDrive folder_id = ifnull(get_crm_record.get("Job_WD_Id"), ""); // If WorkDrive folder ID exists, upload image to WorkDrive if (folder_id != null) { image_folder_upload = zoho.workdrive.uploadFile(rec.Image, folder_id, var, false, "workdrive"); } } }

Explanation

  1. Retrieve the CRM Record: Fetch the CRM record using the CRM ID from Creator.
  2. Check for Existing Attachments: Get related attachments from CRM and iterate to check if the image already exists by comparing filenames.
  3. Download & Attach: If the image does not exist, download it from Creator and attach it to the CRM record.
  4. Upload to WorkDrive: If a WorkDrive folder ID is available in the CRM job record, upload the image to WorkDrive for easy access.

Notes

  1. Job_WD_Id is the WorkDrive folder ID for each job record. 
  2. Connection Names:zcreator: Connection for accessing Zoho Creator API.
  3. workdrive: Connection for accessing Zoho WorkDrive.

External Resources

Post a Comment