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 Books: Generate Bank Text File for Download

What?
This is an article to document how we created a button off a Bill record in ZohoBooks which generates a text file to be sent to a bank and downloads it to the staff member's workstation.

Why?
Why is this a challenge? The file contains bank details and should not be stored anywhere. Generating a text or CSV file and then having it emailed to anyone is an easy task but here we cannot have that file sat on someone's mailbox. It must be downloaded (as in browser downloads it to the computer immediately) and then removed from wherever it was downloaded from...  All within ZohoBooks without using any other apps or software.

How?
Here's how to use it:
  • Staff member clicks on button
  • File downloads to their workstation
Here's what's happening in the background:
  • File is generated
  • FIle is attached to the last record of the source data
  • File identifying number is returned from being attached
  • File is opened in a new tab/window to trigger downloading.
  • File is deleted from attachments based on its identifying number (allows other attachments to remain intact)

Generate the file
The code here is a cut down version just to demonstrate generating a text file and storing this into a variable:
copyraw
//
// initialize
v_CSVString = "Bank Sort Code,Bank Acc. No,Account Holder";
v_CSVString = v_CSVString + "12-34-56,012345678,Joel Lipman";
//
// convert to a TXT file (not a CSV...)
f_BillsExport = v_CSVString.tofile("PaymentRun.txt");
  1.  // 
  2.  // initialize 
  3.  v_CSVString = "Bank Sort Code,Bank Acc. No,Account Holder"
  4.  v_CSVString = v_CSVString + "12-34-56,012345678,Joel Lipman"
  5.  // 
  6.  // convert to a TXT file (not a CSV...) 
  7.  f_BillsExport = v_CSVString.tofile("PaymentRun.txt")

Attach the file
Attach this to any record. Here we'll use the last record used initally to generate this CSV/Text file; which happens to be a bill:
copyraw
//
// build attachment request
m_Attachment = Map();
m_Attachment.put("paramName", "attachment");
m_Attachment.put("content", f_BillsExport);
//
// this variable name is in plural, but as a custom function within ZohoBooks, we know this is just 1 bill record, still...
for each r_Bill in bills
{
	v_BillID = r_Bill.get("bill_id");
}
//
// send attachment request
r_Attachment = invokeurl
[
	url: "https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/attachment?organization_id=123456789"
	type: POST
	files: m_Attachment 
	connection: "zbooks"
];
  1.  // 
  2.  // build attachment request 
  3.  m_Attachment = Map()
  4.  m_Attachment.put("paramName", "attachment")
  5.  m_Attachment.put("content", f_BillsExport)
  6.  // 
  7.  // this variable name is in plural, but as a custom function within ZohoBooks, we know this is just 1 bill record, still... 
  8.  for each r_Bill in bills 
  9.  { 
  10.      v_BillID = r_Bill.get("bill_id")
  11.  } 
  12.  // 
  13.  // send attachment request 
  14.  r_Attachment = invokeUrl 
  15.  [ 
  16.      url: "https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/attachment?organization_id=123456789" 
  17.      type: POST 
  18.      files: m_Attachment 
  19.      connection: "zbooks" 
  20.  ]

Open the file / Download via Browser
We're going to use an openUrl() function here in the hopes that your browser will just begin downloading it (failing this it will open up in the browser and staff member will need to be instructed on how to 'File > Save As...'):
copyraw
//
// if successful
if(r_Attachment.get("code") == 0)
{
	l_DocumentResponse = r_Attachment.get("documents");
	for each r_Doc in l_DocumentResponse
	{
		v_DocumentID = r_Doc .get("document_id");
		break;
	}
	//
	// open/download the file immediately to workstation
	openurl("https://books.zoho.com/api/v3/documents/" + v_DocumentID + "?organization_id=123456789&","new window");
}
  1.  // 
  2.  // if successful 
  3.  if(r_Attachment.get("code") == 0) 
  4.  { 
  5.      l_DocumentResponse = r_Attachment.get("documents")
  6.      for each r_Doc in l_DocumentResponse 
  7.      { 
  8.          v_DocumentID = r_Doc .get("document_id")
  9.          break
  10.      } 
  11.      // 
  12.      // open/download the file immediately to workstation 
  13.      openurl("https://books.zoho.com/api/v3/documents/" + v_DocumentID + "?organization_id=123456789&","new window")
  14.  } 

Delete the file
We need to delete this file from the attachments as well as from the system as it contains bank details. You can skip this step if you're not bothered about storing this file on the system. Note that if you use the endpoint to delete the attachment from the bill, it is still stored in the documents directory of Zoho Books. Deleting the file from the documents directory of Zoho Books (without disassociating it from the attachments), will remove the file permanently. You only need to run either of these as the second one runs both (disassociate and delete):
copyraw
// disassociate as attachment (removes attachment from the Bill but keep in ZohoBooks documents)
r_Detach = invokeurl
[
	url :"https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/attachment/" + v_DocumentID + "?organization_id=123456789"
	type :DELETE
	connection:"zbooks"
];

// remove from attachments and delete permanently from documents in ZohoBooks
r_Detach = invokeurl
[
	url :"https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/documents/" + v_DocumentID + "?organization_id=123456789"
	type :DELETE
	connection:"zbooks"
];
  1.  // disassociate as attachment (removes attachment from the Bill but keep in ZohoBooks documents) 
  2.  r_Detach = invokeUrl 
  3.  [ 
  4.      url :"https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/attachment/" + v_DocumentID + "?organization_id=123456789" 
  5.      type :DELETE 
  6.      connection:"zbooks" 
  7.  ]
  8.   
  9.  // remove from attachments and delete permanently from documents in ZohoBooks 
  10.  r_Detach = invokeUrl 
  11.  [ 
  12.      url :"https://www.zohoapis.com/books/v3/bills/" + v_BillID + "/documents/" + v_DocumentID + "?organization_id=123456789" 
  13.      type :DELETE 
  14.      connection:"zbooks" 
  15.  ]

Caveat(s)
  • The delete process may need to be in a schedule: you can use a custom module in ZohoBooks to store the necessary information of what to delete.

Undocumented extras
Just making a list of things that at-time-of-print of this article aren't in the official Zoho documentation:
  • Query the documents folder
    copyraw
    r_MyDocuments = invokeurl
    [
    	url: "https://www.zohoapis.com/books/v3/documents?organization_id=123456789"
    	type: GET
    	connection: "zbooks"
    ];
    1.  r_MyDocuments = invokeUrl 
    2.  [ 
    3.      url: "https://www.zohoapis.com/books/v3/documents?organization_id=123456789" 
    4.      type: GET 
    5.      connection: "zbooks" 
    6.  ]

Source(s)
Category: Zoho :: Article: 858

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.