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 http://ascentbusiness.co.uk/zoho-support-2. 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 http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices 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 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

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

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: 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
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 - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.