For Zoho Services only:

I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 392 8140 (UK) or by email at You can also visit our website at

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

Zoho Deluge: Associate/Link an Invoice to a Sales Order

This is an article because there was no documentation that I could find that describes how to do this. When an invoice is created, not by clicking on the "convert sales order to invoice" button, I needed a way to programmatically link the sales order to the invoice.
Zoho Deluge: Associate Sales Order to Invoice

The documentation around the API does not detail how to do this. I also couldn't find any search result via Google or DuckDuckGo (can't say for Bing, I never get around to searching that). This took several hours but it is possible, I was just about to give up even after having spoken to Zoho Support... And then I started updating multiple fields at the same time.

Through sweat and perseverance.
The trick is to update both the sales order id and to update the invoice line items with their respective sales order item id value. For our client's purpose, we are running a custom function off the invoice module which:
  1. creates a sales order
  2. checks the returning sales order line items
  3. cycles through the invoice line items to insert the "sales_order_item_id" field
v_InvoiceID = invoice.get("invoice_id");
v_BooksOrgID = organization.get("organization_id");
// a sales order has been created, get its ID (required) and reference (optional)
r_NewSoDetails = r_CreateSO.get("salesorder");
v_NewSoID = r_NewSoDetails.get("salesorder_id");
v_NewRefNum = r_NewSoDetails.get("salesorder_number");
// build up a reference map from the line items of the newly created sales order
m_NewLineItems = Map();
for each  r_NewLineItem in r_NewSoDetails.get("line_items")
    v_NewSoItemID = r_NewLineItem.get("item_id");
    v_NewSoLineItemQuantity = r_NewLineItem.get("quantity").round(0);
    v_NewSoLineItemRate = r_NewLineItem.get("rate");
    m_NewLineItems.put(v_NewSoItemID + "|" + v_NewSoLineItemQuantity + "|" + v_NewSoLineItemRate,r_NewLineItem.get("line_item_id"));
// now loop through the invoice line items and rebuild the list
l_UpdateLineItems = List();
for each  r_OldLineItem in invoice.get("line_items")
    m_LineItem = Map();
    v_OldInvoiceItemID = r_OldLineItem.get("item_id");
    v_OldInvoiceLineItemQuantity = r_OldLineItem.get("quantity");
    v_OldInvoiceItemRate = r_OldLineItem.get("rate");
    v_OldKey = v_OldInvoiceItemID + "|" + v_OldInvoiceLineItemQuantity + "|" + v_OldInvoiceItemRate;
// now update the current invoice with the sales order details
m_UpdateInvoice = Map();
r_Update = zoho.books.updateRecord("Invoices",v_BooksOrgID,v_InvoiceID,m_UpdateInvoice);
info r_Update;
  1.  v_InvoiceID = invoice.get("invoice_id")
  2.  v_BooksOrgID = organization.get("organization_id")
  3.  // 
  4.  // a sales order has been created, get its ID (required) and reference (optional) 
  5.  r_NewSoDetails = r_CreateSO.get("salesorder")
  6.  v_NewSoID = r_NewSoDetails.get("salesorder_id")
  7.  v_NewRefNum = r_NewSoDetails.get("salesorder_number")
  8.  // 
  9.  // build up a reference map from the line items of the newly created sales order 
  10.  m_NewLineItems = Map()
  11.  for each  r_NewLineItem in r_NewSoDetails.get("line_items") 
  12.  { 
  13.      v_NewSoItemID = r_NewLineItem.get("item_id")
  14.      v_NewSoLineItemQuantity = r_NewLineItem.get("quantity").round(0)
  15.      v_NewSoLineItemRate = r_NewLineItem.get("rate")
  16.      m_NewLineItems.put(v_NewSoItemID + "|" + v_NewSoLineItemQuantity + "|" + v_NewSoLineItemRate,r_NewLineItem.get("line_item_id"))
  17.  } 
  18.  // 
  19.  // now loop through the invoice line items and rebuild the list 
  20.  l_UpdateLineItems = List()
  21.  for each  r_OldLineItem in invoice.get("line_items") 
  22.  { 
  23.      m_LineItem = Map()
  24.      v_OldInvoiceItemID = r_OldLineItem.get("item_id")
  25.      m_LineItem.put("item_id",v_OldInvoiceItemID)
  26.      v_OldInvoiceLineItemQuantity = r_OldLineItem.get("quantity")
  27.      m_LineItem.put("quantity",v_OldInvoiceLineItemQuantity.round(0))
  28.      v_OldInvoiceItemRate = r_OldLineItem.get("rate")
  29.      m_LineItem.put("rate",v_OldInvoiceItemRate)
  30.      v_OldKey = v_OldInvoiceItemID + "|" + v_OldInvoiceLineItemQuantity + "|" + v_OldInvoiceItemRate; 
  31.      if(!isnull(m_NewLineItems.get(v_OldKey))) 
  32.      { 
  33.          m_LineItem.put("salesorder_item_id",m_NewLineItems.get(v_OldKey))
  34.      } 
  35.      l_UpdateLineItems.add(m_LineItem)
  36.  } 
  37.  // 
  38.  // now update the current invoice with the sales order details 
  39.  m_UpdateInvoice = Map()
  40.  m_UpdateInvoice.put("line_items",l_UpdateLineItems)
  41.  m_UpdateInvoice.put("reference_number",v_NewRefNum)
  42.  m_UpdateInvoice.put("salesorder_id",v_NewSoID)
  43.  m_UpdateInvoice.put("salesorder_number",v_NewRefNum)
  44.  r_Update = zoho.books.updateRecord("Invoices",v_BooksOrgID,v_InvoiceID,m_UpdateInvoice)
  45.  info r_Update; 
Category: Zoho :: Article: 707

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: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used 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

Related Articles

Joes Revolver Map


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:

Donate to Joel Lipman via PayPal

Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 bc1qjtp4l4ra452wzvuk9a45yfj82zkahsyy2z379y
© 2022 Joel Lipman .com. All Rights Reserved.