This set up allows you to insert subform rows and add to picklist dynamically with values unique to each row on a Zoho Creator subform.
If you dig this, check out our free Zoho training page!
Suppose you have a Creator Form to help a recruitment agency place talents to job openings, where upon submission of the form, it creates a job placement record in CRM and sends an email notification to the employer via CRM. In the Creator Form, you have a subform where on addition of a row, it dynamically adds to a picklist field existing job openings which are records stored in a custom module in CRM. Each job opening is linked to a partner (an Account in CRM), and each Account is linked to several Contacts. Here’s the challenge – users need to be able to select the Contact for each job opening they would like to have the email notification sent to.
Create a map of Account (key) and Contact list (value) and put it in a hidden multi-line field.
Show the Subform and Set Counters
if(input.Confirm == true) { show Employer_Contact_Person; //Counter mp = Map(); string = ""; employerList = List();
Iterate through the Existing Job Opening subform
if(input.Existing_Job_Opening.toList().size() > 0) { for each e in input.Existing_Job_Opening { jo = ifNull(e.Active_Job_Openings,""); if(jo != "") { //Get the Job Opening ID joMap = input.Job_Openings_Map.toMap(); //info joMap; joID = joMap.get(employer).toLong(); info joID;
Get the Contact and Account Name
//Get the Account jobOpening = zoho.crm.getRecordById("Job_Openings",joID); accountid = jobOpening.get("Account_Lookup").get("id").toLong(); account = zoho.crm.getRecordById("Accounts",accountid); //Get the Contacts for later contacts = zoho.crm.getRelatedRecords("Contacts","Accounts",accountid); //Get the Account Name employerName = account.get("Account_Name");
Add the Account Name to the Employer Contact Person subform
//Add that into the Employer Contact Person subform row_n = Zoho_Job_Placements_and_Intros.Employer_Contact_Person(); if(employerName not in employerList) { row_n.Employer=employerName; employerList.add(employerName); //Declare a variable to hold the collection of rows update = Collection(); update.insert(row_n); //Insert the rows into the subform through the variable input.Employer_Contact_Person.insert(update);
Create the Contact Maps and Put in the Respective Multi-Line Fields
if(contacts.size() > 0) { contactList = List(); for each c in contacts { contactList.add(c.get("Full_Name")); string = string + "\"" + c.get("Full_Name") + "\"" + ":" + c.get("id") + ","; } mp.put(employerName,contactList); } } } } }
Update the Maps and Trigger the Hidden Checkbox
//Insert Map 1 input.Employer_Contact_Map = mp.toString(); //Insert Map 2 mapstring = "{" + string + "}"; mapstring = mapstring.removeLastOccurence(","); input.Contact_ID_Map = mapstring; //Trigger the hidden checkbox input.Trigger = true; } else { hide Employer_Contact_Person; if(input.Employer_Contact_Person.toList().size() > 0) { input.Employer_Contact_Person.clear(); } }
Dynamically Add Contact List as Picklist Values in the Employer Contact Person Subform
for each emp in Employer_Contact_Person { mp = input.Employer_Contact_Map.toMap(); emp.Contact_Person:ui.add(mp.get(emp.Employer)); }
Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.
When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit....
Learn to create a customized inventory report with Zoho Analytics. This tutorial contains a link to our GitHub page for SQL code that will help with your table creations....
How nice would it be if you could, at the press of a button, send clients an email w/a Zoho Books invoice? Replete with “Pay Now” buttons that link to PayPal/Stripe/other payment gateways?...
Whether you work primarily out of CRM or the Zoho Finance Suite, you can use Analytics to build commissions dashboards. This involves some fairly simple SQL code....
If you are an inventory manager, this blog post could change your life. If you are not, it will at least teach you how to build some wicked inventory tracking for your business....
Convert fields, related activities, attachments, notes and more from one record to another across modules via custom function....