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 Creator: Add a subform while creating a record

What?
This is an article to document how to include a subform and rows while you are creating a record containing the subform.

Why?
The use case here is for a Quote Builder in Zoho Creator: Create a quote record and include a subform containing the line items. You may have tried code where you add a record first and then add the subform afterwards (insert into <form>[...]) but it can be done all in one go.

How?
Here's a use case example which you will need to adapt to your own but It should do enough (spacing has been added for demo purposes and to make it clearer).

In the below example, my form is called "Quotes" and my subform is called "Line_Items":
copyraw
// initialize variables
// ... this is a demo so ... do your own ...
//
// get source data
r_QuoteDetails = zoho.crm.getRecordById("Quotes", 123456789012345678);
//
// transform variables for main record
v_QuoteName = ifnull(r_QuoteDetails.get("Name"),"Test Quote");
if(!isNull(r_QuoteDetails.get("Contact_Name")))
{
    r_ContactDetails    = zoho.crm.getRecordById("Contacts", r_QuoteDetails.get("Contact_Name").get("id"));
    v_ContactFname      = r_ContactDetails.get("First_Name");
    v_ContactSname      = r_ContactDetails.get("Last_Name");
    v_AddressLine1      = r_ContactDetails.get("Street");
    v_AddressCity       = r_ContactDetails.get("City");
    v_AddressState      = r_ContactDetails.get("State");
    v_AddressZip        = r_ContactDetails.get("Zip");
    v_AddressCountry    = r_ContactDetails.get("Country");
}
//
// get line items from source and populate this subform
l_QuotedItems = r_QuoteDetails.get("Product_Details");
c_LineItems = Collection();
for each  m_LineItem in l_QuotedItems
{
    r_Row               = Quotes.Line_Items();
    r_Row.Product       = m_LineItem.get("Product");
    r_Row.Quantity      = m_LineItem.get("Quantity");
    r_Row.List_Price    = m_LineItem.get("List_Price");
    r_Row.Tax           = m_LineItem.get("Tax");
    r_Row.Discount      = m_LineItem.get("Discount");
    r_Row.Total         = m_LineItem.get("Line_Item_Total");
    c_LineItems.insert(r_Row);
}
//
// create creator record
r_Create = insert into Quotes
[
    Added_User=zoho.loginuser
    Quote_Name=v_QuoteName
    Contact_Name.first_name=v_ContactFname
    Contact_Name.last_name=v_ContactSname
    Billing_Address.address_line_1=v_AddressLine1
    Billing_Address.district_city=v_AddressCity
    Billing_Address.state_province=v_AddressCity
    Billing_Address.postal_Code=v_AddressZip
    Billing_Address.country=v_AddressCountry
    Line_Items=c_LineItems
];
  1.  // initialize variables 
  2.  // ... this is a demo so ... do your own ... 
  3.  // 
  4.  // get source data 
  5.  r_QuoteDetails = zoho.crm.getRecordById("Quotes", 123456789012345678)
  6.  // 
  7.  // transform variables for main record 
  8.  v_QuoteName = ifnull(r_QuoteDetails.get("Name"),"Test Quote")
  9.  if(!isNull(r_QuoteDetails.get("Contact_Name"))) 
  10.  { 
  11.      r_ContactDetails    = zoho.crm.getRecordById("Contacts", r_QuoteDetails.get("Contact_Name").get("id"))
  12.      v_ContactFname      = r_ContactDetails.get("First_Name")
  13.      v_ContactSname      = r_ContactDetails.get("Last_Name")
  14.      v_AddressLine1      = r_ContactDetails.get("Street")
  15.      v_AddressCity       = r_ContactDetails.get("City")
  16.      v_AddressState      = r_ContactDetails.get("State")
  17.      v_AddressZip        = r_ContactDetails.get("Zip")
  18.      v_AddressCountry    = r_ContactDetails.get("Country")
  19.  } 
  20.  // 
  21.  // get line items from source and populate this subform 
  22.  l_QuotedItems = r_QuoteDetails.get("Product_Details")
  23.  c_LineItems = Collection()
  24.  for each  m_LineItem in l_QuotedItems 
  25.  { 
  26.      r_Row               = Quotes.Line_Items()
  27.      r_Row.Product       = m_LineItem.get("Product")
  28.      r_Row.Quantity      = m_LineItem.get("Quantity")
  29.      r_Row.List_Price    = m_LineItem.get("List_Price")
  30.      r_Row.Tax           = m_LineItem.get("Tax")
  31.      r_Row.Discount      = m_LineItem.get("Discount")
  32.      r_Row.Total         = m_LineItem.get("Line_Item_Total")
  33.      c_LineItems.insert(r_Row)
  34.  } 
  35.  // 
  36.  // create creator record 
  37.  r_Create = insert into Quotes 
  38.  [ 
  39.      Added_User=zoho.loginuser 
  40.      Quote_Name=v_QuoteName 
  41.      Contact_Name.first_name=v_ContactFname 
  42.      Contact_Name.last_name=v_ContactSname 
  43.      Billing_Address.address_line_1=v_AddressLine1 
  44.      Billing_Address.district_city=v_AddressCity 
  45.      Billing_Address.state_province=v_AddressCity 
  46.      Billing_Address.postal_Code=v_AddressZip 
  47.      Billing_Address.country=v_AddressCountry 
  48.      Line_Items=c_LineItems 
  49.  ]

From the documentation
Zoho Documentation - Insert Rows in Subform

Additional
  • Note that any bidirectional relation field that exists will be prepopulated using the method above.
  • Clear subform of all its rows: input.<subForm_linkName>.clear();
  • Changing the picklist/dropdown options in a subform row (applies overall rather than per row):
    copyraw
    clear <mainForm_linkName>.<subForm_linkName>.<subForm_field_linkName>;
    <mainForm_linkName>.<subForm_linkName>.<subForm_field_linkName>:ui.add(<dropdown_option_1>);
    1.  clear <mainForm_linkName>.<subForm_linkName>.<subForm_field_linkName>
    2.  <mainForm_linkName>.<subForm_linkName>.<subForm_field_linkName>:ui.add(<dropdown_option_1>)

Source(s):
Category: Zoho Creator :: Article: 287

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