For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

Zoho CRM & Creator: Download attachment and upload to Creator file field

What?
A super quick article on how to download an attachment from CRM and upload to a "file upload" field in Creator.

Why?
My use case here is that we are creating a Creator app that will show the attachments on a CRM contact record (and be clickable). The complication here is that the user can use the Creator form to add a new attachment that will eventually be uploaded back to CRM.

How?
At time of print, things have moved on and based on the Zoho official forums, this used to be a daunting task. Not anymore at least from what I've seen.

You could try adding a subform to Creator but have it as a blank form rather than a bidirectional form as in this example, the parent record doesn't yet exist... The cheat here is that we actually want the user to be able to click and download/open the attachments on the CRM record from within the Creator app. As for the add a new attachment, well that's just functionality.

Here's my Creator form (well the part for the attachments):
  • An attachments section to hold a notes field.
  • A notes field called "Note_Attachments" (this will display a HTML table with click-to-download files)
  • A blank subform callled "Attachments" (links to a form called "Documents")
Zoho CRM & Creator: Download attachment and upload to Creator file field: Parent Creator Form

Here's the Creator form to hold the Attachments:
  • Parent Record (a single line that will be a unique ref to prevent downloading the same record again and again)
  • Document Name (a single line that will be the name of the file including its extension)
  • Document (the file upload field)
  • Downloaded (a picklist with the options "Downloaded" and "Pending Upload")
Zoho CRM & Creator: Download attachment and upload to Creator file field: Document Creator Form

Here's the code for the parent form to download the attachments and upload them to the Creator "Document" form:
copyraw
//
// get attachments
v_NoteAttachments = "<table class='jl-table-info jl-table-attachments'>";
m_SortCriteria = Map();
m_SortCriteria.put("sort_by","Created_Time");
m_SortCriteria.put("sort_order","desc");
l_Attachments = zoho.crm.getRelatedRecords("Attachments","Contacts",v_CrmContactID,1,200,m_SortCriteria);
for each  r_Attachment in l_Attachments
{
	if(r_Attachment.get("id") != null)
	{
		v_AttachmentEndpoint = "https://www.zohoapis.com/crm/v2/Contacts/" + v_CrmContactID + "/Attachments/" + r_Attachment.get("id");
		r_Download = invokeurl
		[
			url :v_AttachmentEndpoint
			type :GET
			connection:"ab_crm"
		];
		r_Download.setParamName("file");
		r_CheckIfDocumentAlreadyExists = Document[Parent_Record == v_CrmContactID.toString() && Document_Name == r_Attachment.get("File_Name")];
		if(r_CheckIfDocumentAlreadyExists.count() > 0)
		{
			r_NewDocumentRecord = Document[ID == r_CheckIfDocumentAlreadyExists.ID];
			v_DateAdded = r_NewDocumentRecord.Added_Time.toString("E, d MMM yyyy HH:mm");
		}
		else
		{
			r_Document = insert into Document
			[
				Added_User=zoho.loginuser
				Document_Name=r_Attachment.get("File_Name")
				Document_File=r_Download
				Downloaded="Downloaded"
				Parent_Record=v_CrmContactID.toString()
			];
			r_NewDocumentRecord = Document[ID == r_Document];
			v_DateAdded = r_NewDocumentRecord.Added_Time.toString("E, d MMM yyyy HH:mm");
		}
		v_LinkToDownload = "<a href='https://creator.zoho.com/file" + zoho.appuri + "All_Documents/" + r_NewDocumentRecord.ID + "/Document_File/download?filepath=/" + r_NewDocumentRecord.Document_File + "'>" + r_NewDocumentRecord.Document_Name + "</a>";
		v_NoteAttachments = v_NoteAttachments + "<tr><td>" + v_DateAdded + "</td><td style='font-weight:700;'>" + v_LinkToDownload + "</td></tr>";
	}
}
v_NoteAttachments = v_NoteAttachments + "</table>";
input.Note_Attachments = v_NoteAttachments;
  1.  // 
  2.  // get attachments 
  3.  v_NoteAttachments = "<table class='jl-table-info jl-table-attachments'>"
  4.  m_SortCriteria = Map()
  5.  m_SortCriteria.put("sort_by","Created_Time")
  6.  m_SortCriteria.put("sort_order","desc")
  7.  l_Attachments = zoho.crm.getRelatedRecords("Attachments","Contacts",v_CrmContactID,1,200,m_SortCriteria)
  8.  for each  r_Attachment in l_Attachments 
  9.  { 
  10.      if(r_Attachment.get("id") != null) 
  11.      { 
  12.          v_AttachmentEndpoint = "https://www.zohoapis.com/crm/v2/Contacts/" + v_CrmContactID + "/Attachments/" + r_Attachment.get("id")
  13.          r_Download = invokeUrl 
  14.          [ 
  15.              url :v_AttachmentEndpoint 
  16.              type :GET 
  17.              connection:"ab_crm" 
  18.          ]
  19.          r_Download.setParamName("file")
  20.          r_CheckIfDocumentAlreadyExists = Document[Parent_Record == v_CrmContactID.toString() && Document_Name == r_Attachment.get("File_Name")]
  21.          if(r_CheckIfDocumentAlreadyExists.count() > 0) 
  22.          { 
  23.              r_NewDocumentRecord = Document[ID == r_CheckIfDocumentAlreadyExists.ID]
  24.              v_DateAdded = r_NewDocumentRecord.Added_Time.toString("E, d MMM yyyy HH:mm")
  25.          } 
  26.          else 
  27.          { 
  28.              r_Document = insert into Document 
  29.              [ 
  30.                  Added_User=zoho.loginuser 
  31.                  Document_Name=r_Attachment.get("File_Name") 
  32.                  Document_File=r_Download 
  33.                  Downloaded="Downloaded" 
  34.                  Parent_Record=v_CrmContactID.toString() 
  35.              ]
  36.              r_NewDocumentRecord = Document[ID == r_Document]
  37.              v_DateAdded = r_NewDocumentRecord.Added_Time.toString("E, d MMM yyyy HH:mm")
  38.          } 
  39.          v_LinkToDownload = "<a href='https://creator.zoho.com/file" + zoho.appuri + "All_Documents/" + r_NewDocumentRecord.ID + "/Document_File/download?filepath=/" + r_NewDocumentRecord.Document_File + "'>" + r_NewDocumentRecord.Document_Name + "</a>"
  40.          v_NoteAttachments = v_NoteAttachments + "<tr><td>" + v_DateAdded + "</td><td style='font-weight:700;'>" + v_LinkToDownload + "</td></tr>"
  41.      } 
  42.  } 
  43.  v_NoteAttachments = v_NoteAttachments + "</table>"
  44.  input.Note_Attachments = v_NoteAttachments; 

Here's the code at the end of the parent form to hide the columns I don't need the user to see (I'll populate these by code):
copyraw
hide Attachments.Parent_Record;
hide Attachments.Document_Name;
hide Attachments.Downloaded;
  1.  hide Attachments.Parent_Record; 
  2.  hide Attachments.Document_Name; 
  3.  hide Attachments.Downloaded; 

Here's the code I use when a "Addition of a row" workflow is triggered on that subform. This makes sure I don't download it again and create a new Creator record to hold the same file but in a new record, as well as include the marker to check when uploading the files back to CRM:
copyraw
row.Parent_Record=input.CRM_Contact;
row.Downloaded="Pending Upload";
  1.  row.Parent_Record=input.CRM_Contact; 
  2.  row.Downloaded="Pending Upload"

Here's the code I use when uploading a file to the newly added row in that subform (on user input). This sets the document name for display later:
copyraw
if(!isnull(row.Document_File))
{
	v_FileDetected = row.Document_File;
	if(v_FileDetected.contains("_"))
	{
		v_SubstringStart = v_FileDetected.indexOf("_");
		v_FilenameDetected = v_FileDetected.subString(v_SubstringStart + 1);
		v_FilenameFormatted = v_FilenameDetected.replaceAll("_"," ");
		row.Document_Name=v_FilenameFormatted;
	}
}
  1.  if(!isnull(row.Document_File)) 
  2.  { 
  3.      v_FileDetected = row.Document_File; 
  4.      if(v_FileDetected.contains("_")) 
  5.      { 
  6.          v_SubstringStart = v_FileDetected.indexOf("_")
  7.          v_FilenameDetected = v_FileDetected.subString(v_SubstringStart + 1)
  8.          v_FilenameFormatted = v_FilenameDetected.replaceAll("_"," ")
  9.          row.Document_Name=v_FilenameFormatted; 
  10.      } 
  11.  } 

And finally, with a bit of CSS, this is what the end product looks like:
Zoho CRM & Creator: Download attachment and upload to Creator file field: How it looks

Category: Zoho :: Article: 809

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.