For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho Books: Generate Bank Text File for Download

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 Books :: Article: 387

Joes Word Cloud

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

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

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