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: Updating a CRM record Custom Line Items using API v7

What?
This is a quick bit of code for my reference so that I don't have to keep finding a function that gives me the syntax of how to either create or update a record using invokeUrl.

Why?
Because my designers keep including custom fields in their transactional modules line items (quotes, sales orders, invoices, purchase orders). The only way to update these are by using the API and deluge function invokeURL rather than the usual shortcode of zoho.crm.updateRecord() or zoho.crm.createRecord().

How?
This is somewhere in the official documentation but here's the bits that I need:

Updating a record with PUT (note that id needs passed for each row otherwise you will end up with duplicate line items):
copyraw
/* *******************************************************************************
	Function:       void automation.fn_Quotes_OnEdit(int p_QuoteID)
	Label:          Fn - Quotes - On Edit
	Trigger:        Used in a workflow when a quote is modified
	Purpose:		Actions when a quote is modified
	Inputs:         int p_QuoteID - the ID of the CRM Quote Record
	Outputs:        void

	Date Created:   2024-12-10 (Joel Lipman)
					- Initial release
	Date Modified:	???
					- ???

	More Information:
					Any information that may help

	******************************************************************************* */
//
// initialize
m_UpdateQuote = Map();
//
// get quote details
v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID;
r_QuoteDetails = invokeurl
[
	url :v_Endpoint
	type :GET
	connection:"zcrm"
];
l_RecordData = ifnull(r_QuoteDetails.get("data"),List());
for each  m_RecordData in l_RecordData
{
	//
	// apply changes to any of the line items
	l_NewLineItems = List();
	if(!isNull(m_RecordData.get("id")))
	{
		for each  m_LineItem in m_RecordData.get("Quoted_Items")
		{
			m_NewLineItem = Map();
			m_NewLineItem.put("id",m_LineItem.get("id"));
			m_NewLineItem.put("Description",m_LineItem.get("Description"));
			m_NewLineItem.put("Discount",m_LineItem.get("Discount"));
			m_NewLineItem.put("CUSTOM_FIELD_1",m_LineItem.get("CUSTOM_FIELD_1"));
			m_NewLineItem.put("CUSTOM_FIELD_2",m_LineItem.get("CUSTOM_FIELD_2"));
			m_NewLineItem.put("Product_Name",m_LineItem.get("Product_Name"));
			m_NewLineItem.put("Quantity",m_LineItem.get("Quantity"));
			m_NewLineItem.put("List_Price",m_LineItem.get("List_Price"));
			l_NewLineItems.add(m_NewLineItem);
		}
	}
}
//
// if there is reason to update it then let's update CRM API v7 style
if(l_NewLineItems.size() > 0)
{
	// 
	// build request to send to CRM v7
	// m_RecordData should have value from last iteration
	m_UpdateQuote.put("Subject",m_RecordData.get("Subject"));
	m_UpdateQuote.put("Quoted_Items",l_NewLineItems);
	l_RecordsToSend = List();
	l_RecordsToSend.add(m_UpdateQuote);
	m_Data = Map();
	m_Data.put("data",l_RecordsToSend);
	// 
	// this is REST API so by default all triggers run.  Use an empty list to stop or prevent these from triggering. 
	m_Data.put("trigger",List());
	v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID;
	r_QuoteDetails = invokeurl
	[
		url :v_Endpoint
		type :PUT
		parameters:m_Data.toString()
		connection:"zcrm"
	];
	info r_QuoteDetails;
}
  1.  /* ******************************************************************************* 
  2.      Function:       void automation.fn_Quotes_OnEdit(int p_QuoteID) 
  3.      Label:          Fn - Quotes - On Edit 
  4.      Trigger:        Used in a workflow when a quote is modified 
  5.      Purpose:        Actions when a quote is modified 
  6.      Inputs:         int p_QuoteID - the ID of the CRM Quote Record 
  7.      Outputs:        void 
  8.   
  9.      Date Created:   2024-12-10 (Joel Lipman) 
  10.                      - Initial release 
  11.      Date Modified:    ??? 
  12.                      - ??? 
  13.   
  14.      More Information: 
  15.                      Any information that may help 
  16.   
  17.      ******************************************************************************* */ 
  18.  // 
  19.  // initialize 
  20.  m_UpdateQuote = Map()
  21.  // 
  22.  // get quote details 
  23.  v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID; 
  24.  r_QuoteDetails = invokeUrl 
  25.  [ 
  26.      url :v_Endpoint 
  27.      type :GET 
  28.      connection:"zcrm" 
  29.  ]
  30.  l_RecordData = ifnull(r_QuoteDetails.get("data"),List())
  31.  for each  m_RecordData in l_RecordData 
  32.  { 
  33.      // 
  34.      // apply changes to any of the line items 
  35.      l_NewLineItems = List()
  36.      if(!isNull(m_RecordData.get("id"))) 
  37.      { 
  38.          for each  m_LineItem in m_RecordData.get("Quoted_Items") 
  39.          { 
  40.              m_NewLineItem = Map()
  41.              m_NewLineItem.put("id",m_LineItem.get("id"))
  42.              m_NewLineItem.put("Description",m_LineItem.get("Description"))
  43.              m_NewLineItem.put("Discount",m_LineItem.get("Discount"))
  44.              m_NewLineItem.put("CUSTOM_FIELD_1",m_LineItem.get("CUSTOM_FIELD_1"))
  45.              m_NewLineItem.put("CUSTOM_FIELD_2",m_LineItem.get("CUSTOM_FIELD_2"))
  46.              m_NewLineItem.put("Product_Name",m_LineItem.get("Product_Name"))
  47.              m_NewLineItem.put("Quantity",m_LineItem.get("Quantity"))
  48.              m_NewLineItem.put("List_Price",m_LineItem.get("List_Price"))
  49.              l_NewLineItems.add(m_NewLineItem)
  50.          } 
  51.      } 
  52.  } 
  53.  // 
  54.  // if there is reason to update it then let's update CRM API v7 style 
  55.  if(l_NewLineItems.size() > 0) 
  56.  { 
  57.      // 
  58.      // build request to send to CRM v7 
  59.      // m_RecordData should have value from last iteration 
  60.      m_UpdateQuote.put("Subject",m_RecordData.get("Subject"))
  61.      m_UpdateQuote.put("Quoted_Items",l_NewLineItems)
  62.      l_RecordsToSend = List()
  63.      l_RecordsToSend.add(m_UpdateQuote)
  64.      m_Data = Map()
  65.      m_Data.put("data",l_RecordsToSend)
  66.      // 
  67.      // this is REST API so by default all triggers run.  Use an empty list to stop or prevent these from triggering. 
  68.      m_Data.put("trigger",List())
  69.      v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID; 
  70.      r_QuoteDetails = invokeUrl 
  71.      [ 
  72.          url :v_Endpoint 
  73.          type :PUT 
  74.          parameters:m_Data.toString() 
  75.          connection:"zcrm" 
  76.      ]
  77.      info r_QuoteDetails; 
  78.  } 

Creating a record
Pretty much the same as above but instead of the method/type PUT you will use POST with an endpoint of https://www.zohoapis.com/crm/v7/Quotes.

Showing Off
Just a note here for myself where using invokeAPI over invokeURL:
copyraw
// 
// retrieve record details
r_SoDetails = invokeapi
[
	service :zohocrm
	path :"/crm/v7/Sales_Orders/" + p_SalesOrderID
	type :GET
	connection:"zcrm"
];
l_SoDetails = ifnull(r_SoDetails.get("data"),List());
m_SoDetails = if(l_SoDetails.size() > 0,l_SoDetails.get(0),Map());
info "Sales Order Record Details: ";
info m_SoDetails;
  1.  // 
  2.  // retrieve record details 
  3.  r_SoDetails = invokeapi 
  4.  [ 
  5.      service :zohocrm 
  6.      path :"/crm/v7/Sales_Orders/" + p_SalesOrderID 
  7.      type :GET 
  8.      connection:"zcrm" 
  9.  ]
  10.  l_SoDetails = ifnull(r_SoDetails.get("data"),List())
  11.  m_SoDetails = if(l_SoDetails.size() > 0,l_SoDetails.get(0),Map())
  12.  info "Sales Order Record Details: "
  13.  info m_SoDetails; 
Where format/syntax is:
copyraw
<variable> = invokeapi
[
	service: <service>
	path: <path>
	type: <request_type>
	parameters: <expression>
	connection: <connection_name>
];
  1.  <variable> = invokeapi 
  2.  [ 
  3.      service: <service> 
  4.      path: <path> 
  5.      type: <request_type> 
  6.      parameters: <expression> 
  7.      connection: <connection_name> 
  8.  ]

Additional Note(s):
  • The trigger input can be workflow, approval, blueprint, pathfinder, or orchestration(for the Journey Builder feature). If "trigger" is not mentioned, the automation actions related to the API will get executed. Enter the trigger value as [] to not execute the workflows. [1]
  • To remove or delete a line item when using invokeURL and the PUT method, submit the line item again with its ID as well as a key called "_delete" as per the following snippet:
    copyraw
    //
    // initialize
    m_UpdateQuote = Map();
    //
    // get quote details
    v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID;
    r_QuoteDetails = invokeurl
    [
    	url :v_Endpoint
    	type :GET
    	connection:"zcrm"
    ];
    l_RecordData = ifnull(r_QuoteDetails.get("data"),List());
    for each  m_RecordData in l_RecordData
    {
    	//
    	// apply changes to any of the line items
    	l_NewLineItems = List();
    	if(!isNull(m_RecordData.get("id")))
    	{
    		for each  m_LineItem in m_RecordData.get("Quoted_Items")
    		{
    			if(!isNull(m_LineItem.get("id")) && !m_LineItem.get("Optional"))
    			{
    				// add here line items that will be added or updated
    				m_NewLineItem = Map();
    				m_NewLineItem.put("id",m_LineItem.get("id"));
    				m_NewLineItem.put("Description",m_LineItem.get("Description"));
    				m_NewLineItem.put("Discount",m_LineItem.get("Discount"));
    				m_NewLineItem.put("CUSTOM_FIELD_1",m_LineItem.get("CUSTOM_FIELD_1"));
    				m_NewLineItem.put("CUSTOM_FIELD_2",m_LineItem.get("CUSTOM_FIELD_2"));
    				m_NewLineItem.put("Product_Name",m_LineItem.get("Product_Name"));
    				m_NewLineItem.put("Quantity",m_LineItem.get("Quantity"));
    				m_NewLineItem.put("List_Price",m_LineItem.get("List_Price"));
    				l_NewLineItems.add(m_NewLineItem);
    			} 
    			else 
    			{
    				// add here line items to delete / remove / omit
    				m_NewLineItem = Map();
    				m_NewLineItem.put("id",m_LineItem.get("id"));
    				m_NewLineItem.put("_delete",null);
    				l_NewLineItems.add(m_NewLineItem);
    			}
    		}
    	}
    }
    //
    // if there is reason to update it then let's update CRM API v7 style
    if(l_NewLineItems.size() > 0)
    {
    	// 
    	m_UpdateQuote.put("Subject",m_RecordData.get("Subject"));
    	m_UpdateQuote.put("Quoted_Items",l_NewLineItems);
    	l_RecordsToSend = List();
    	l_RecordsToSend.add(m_UpdateQuote);
    	m_Data = Map();
    	m_Data.put("data",l_RecordsToSend);
    	// 
    	// this is REST API so by default all triggers run.  Use an list to specify any triggers on update. Use an empty list to stop any. 
    	m_Data.put("trigger",{"workflow","approval"});
    	v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID;
    	r_QuoteDetails = invokeurl
    	[
    		url :v_Endpoint
    		type :PUT
    		parameters:m_Data.toString()
    		connection:"zcrm"
    	];
    	info r_QuoteDetails;
    }
    1.  // 
    2.  // initialize 
    3.  m_UpdateQuote = Map()
    4.  // 
    5.  // get quote details 
    6.  v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID; 
    7.  r_QuoteDetails = invokeUrl 
    8.  [ 
    9.      url :v_Endpoint 
    10.      type :GET 
    11.      connection:"zcrm" 
    12.  ]
    13.  l_RecordData = ifnull(r_QuoteDetails.get("data"),List())
    14.  for each  m_RecordData in l_RecordData 
    15.  { 
    16.      // 
    17.      // apply changes to any of the line items 
    18.      l_NewLineItems = List()
    19.      if(!isNull(m_RecordData.get("id"))) 
    20.      { 
    21.          for each  m_LineItem in m_RecordData.get("Quoted_Items") 
    22.          { 
    23.              if(!isNull(m_LineItem.get("id")) && !m_LineItem.get("Optional")) 
    24.              { 
    25.                  // add here line items that will be added or updated 
    26.                  m_NewLineItem = Map()
    27.                  m_NewLineItem.put("id",m_LineItem.get("id"))
    28.                  m_NewLineItem.put("Description",m_LineItem.get("Description"))
    29.                  m_NewLineItem.put("Discount",m_LineItem.get("Discount"))
    30.                  m_NewLineItem.put("CUSTOM_FIELD_1",m_LineItem.get("CUSTOM_FIELD_1"))
    31.                  m_NewLineItem.put("CUSTOM_FIELD_2",m_LineItem.get("CUSTOM_FIELD_2"))
    32.                  m_NewLineItem.put("Product_Name",m_LineItem.get("Product_Name"))
    33.                  m_NewLineItem.put("Quantity",m_LineItem.get("Quantity"))
    34.                  m_NewLineItem.put("List_Price",m_LineItem.get("List_Price"))
    35.                  l_NewLineItems.add(m_NewLineItem)
    36.              } 
    37.              else 
    38.              { 
    39.                  // add here line items to delete / remove / omit 
    40.                  m_NewLineItem = Map()
    41.                  m_NewLineItem.put("id",m_LineItem.get("id"))
    42.                  m_NewLineItem.put("_delete",null)
    43.                  l_NewLineItems.add(m_NewLineItem)
    44.              } 
    45.          } 
    46.      } 
    47.  } 
    48.  // 
    49.  // if there is reason to update it then let's update CRM API v7 style 
    50.  if(l_NewLineItems.size() > 0) 
    51.  { 
    52.      // 
    53.      m_UpdateQuote.put("Subject",m_RecordData.get("Subject"))
    54.      m_UpdateQuote.put("Quoted_Items",l_NewLineItems)
    55.      l_RecordsToSend = List()
    56.      l_RecordsToSend.add(m_UpdateQuote)
    57.      m_Data = Map()
    58.      m_Data.put("data",l_RecordsToSend)
    59.      // 
    60.      // this is REST API so by default all triggers run.  Use an list to specify any triggers on update. Use an empty list to stop any. 
    61.      m_Data.put("trigger",{"workflow","approval"})
    62.      v_Endpoint = "https://www.zohoapis.com/crm/v7/Quotes/" + p_QuoteID; 
    63.      r_QuoteDetails = invokeUrl 
    64.      [ 
    65.          url :v_Endpoint 
    66.          type :PUT 
    67.          parameters:m_Data.toString() 
    68.          connection:"zcrm" 
    69.      ]
    70.      info r_QuoteDetails; 
    71.  } 

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

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
© 2025 Joel Lipman .com. All Rights Reserved.