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 http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

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 http://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 :: Article: 750

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.