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 Deluge: Associate/Link an Invoice to a Sales Order

What?
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

Why?
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.

How?
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
copyraw
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");
    m_LineItem.put("item_id",v_OldInvoiceItemID);
    v_OldInvoiceLineItemQuantity = r_OldLineItem.get("quantity");
    m_LineItem.put("quantity",v_OldInvoiceLineItemQuantity.round(0));
    v_OldInvoiceItemRate = r_OldLineItem.get("rate");
    m_LineItem.put("rate",v_OldInvoiceItemRate);
    v_OldKey = v_OldInvoiceItemID + "|" + v_OldInvoiceLineItemQuantity + "|" + v_OldInvoiceItemRate;
    if(!isnull(m_NewLineItems.get(v_OldKey)))
    {
        m_LineItem.put("salesorder_item_id",m_NewLineItems.get(v_OldKey));
    }
    l_UpdateLineItems.add(m_LineItem);
}
//
// now update the current invoice with the sales order details
m_UpdateInvoice = Map();
m_UpdateInvoice.put("line_items",l_UpdateLineItems);
m_UpdateInvoice.put("reference_number",v_NewRefNum);
m_UpdateInvoice.put("salesorder_id",v_NewSoID);
m_UpdateInvoice.put("salesorder_number",v_NewRefNum);
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; 

Update 2023
If the above doesn't work, consider making an API call to the following endpoint:
copyraw
m_Params = Map();
m_Params.put("invoice_ids", <v_InvoiceID>);
m_Params.put("organization_id", <v_BooksOrgID>);
r_Associate = invokeUrl
[
    url: "https://www.zohoapis.eu/books/v3/invoices/mapwithorder"
    type: POST
    parameters: m_Params
    connection: "zbooks"

]
  1.  m_Params = Map()
  2.  m_Params.put("invoice_ids", <v_InvoiceID>)
  3.  m_Params.put("organization_id", <v_BooksOrgID>)
  4.  r_Associate = invokeUrl 
  5.  [ 
  6.      url: "https://www.zohoapis.eu/books/v3/invoices/mapwithorder" 
  7.      type: POST 
  8.      parameters: m_Params 
  9.      connection: "zbooks" 
  10.   
  11.  ] 

copyraw
m_Params = Map();
m_Params.put("line_items", <l_UpdateLineItems>);
m_Params.put("organization_id", <v_BooksOrgID>);
r_Associate = invokeUrl
[
    url: "https://www.zohoapis.eu/books/v3/invoices/fromsalesorder"
    type: POST
    parameters: m_Params
    connection: "zbooks"

]
  1.  m_Params = Map()
  2.  m_Params.put("line_items", <l_UpdateLineItems>)
  3.  m_Params.put("organization_id", <v_BooksOrgID>)
  4.  r_Associate = invokeUrl 
  5.  [ 
  6.      url: "https://www.zohoapis.eu/books/v3/invoices/fromsalesorder" 
  7.      type: POST 
  8.      parameters: m_Params 
  9.      connection: "zbooks" 
  10.   
  11.  ] 

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: 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.