Record Collection Tips

Record Collection Tips

If anyone ever sales they've never written bad code they are either lying or they are God himself. 


I starting using Zoho in Feb of 09 and like almost everyone that comes to Zoho Creator; I was looking for a way to make my business processes better. This led me to the wonderful world of Deluge Script! 


I would like to Deluge Script learning curve, well, less curvaceous for many of the new DS'ers out there. One aspect about Deluge Script that I immediately picked up on and enjoyed is how you do looping and record collection.. 


For you scripting novices out there. Zoho has done a VERY great job on making loops and record collection for us EASY!


Here's a really basic loop in JAVASCRIPT....


for(var=startvalue;var<=endvalue;var=var+increment)
{


}


Here's the same basic loop in Zoho


for each variable in myRecordCollection
{
      //do this
}


NOW, the other uber wonderful thing that I fell in love with! RECORD COLLECTION! Ok, first let me just say how annoyed I get when Deluge Script developers (with very little experience outside DS) start complaining about missing features and what not. Well, let's talk about what Zoho Creator ABSOLUTELY NAILED! 


Do you know how nice we ZC users have it in regards to collecting records? 


DS let's you write both client side and server side scripting ALL IN ONE. Normally, a regular developer has to write his html views, forms, user input actions, event listeners all in javascript, html and css THEN call a server side language script which connects to a database, creates a query, executes the query, formats the query data into the desired format, and sends it back to the client! ugh!


Yes, yes. I know all the rebuttals about separating your app into  say an MVC (model, view, controller) architecture, using frameworks with ORM capabilities making SQL queries obsolete and so on. BUT, for the small business IT guy that needs a quick solid solution, you can't beat the simplicity of the inline DS query. 


Also, might I just say how nice it is to write my queries in ECMA' esque language! While I do know $jquery, javascript, SQL, and PHP. It's just nice having this cute little DS language to do "most" of what I need it to do. 


Ok, on to the guts.. 


Because ZC caters to the novice developer with very little experience in web development, one often sees many mistakes made in how DS is used. I was THIS GUY! Here are some of my embarrassing past practices and how I do it now. ZC employees and power users have a good smirk or laugh at my expense 



Collecting based on one field with many values

Before : 


myRecords = records[first_name == "John" || first_name == "Sue" || first_name == "Charles"]


Now : 


myList = {"John","Sue","Charles"};


myRecords = records[first_name in myList]


OR Even


myRecords = records[first_name in {"John","Sue","Charles"}];



Making a list out of record fields

Before : (YUCK!)


myList = List();


for each r in records
{
      if(field == "value")
      {
            myList.add(r.field);
      }
}


Now : (AVOID THE LOOP)


myRecords = records[field == "value"];
myList = myRecords.field.getALL();



Making a unique list out of record fields

Before : 


myUniqueList = List();


for each r in records
{
      if(!myUniqueList.contains(r.field))
      {
            myUniqueList.add(r.field);
      }
}


Now : (take the collection offline)


myUniqueList = {};


myRecords = records;
myFieldList = myRecords.field.getAll();
for each r in myFieldList
{
      if(!myUniqueList.contains(r))
      {
            myUniqueList.add(r)
      }
}


NOTE : Haven't tested to see whether this is actually a performance gain but it seems that looping through a list is faster than looping through records. 



Updating records in one form based on another.

Before : THE WORST!

for each r in form1
{
      if(r.field1 == "value")
      {
            form2Record = form2[field2 == r.field1];
            form2Record.field2 = "New Value";
      }
}

Before : a little better by removing if operator and reducing size of records before loop. Also, USE THE ID along with a stored related id (don't forget to set the number fields char limit to 25)!

for each r in form1[field1 == "value"]
{
      form2Record = form2[form1_id == r.ID];
      form2Record.field2 = "New Value";
}


Now : Waaaay  BETTER

form1Records = form1[field1 == "value"];
form1RecordList = form1Records.ID.getAll();

form2Records = form2[form1_Id in form1RecordList];
form2Records.field2 = "New Value";


Creating a "record reduce" based on many table values related to another.

Before : never thought about it :)

Now : 

lastNameRecords = namesForm[last_name != ""] sort by Added_Time desc range from 1 to 100;
lastNameList = lastNameRecords.last_name.getAll();

locationRecords = locationsForm[open == "yes"]
locationsList = locationsRecords.location.getAll();

//new members in open locations

lastHundredMembers = members[last_name in lastNameList && location in locationsList];


Ok this was a very short list of tips. But, I plan on adding to it later. Anyone, else have code "yucks" from the past and your present solution POST IT! Doesn't have to be about record Collection. 

































    Access your files securely from anywhere









                          Zoho Developer Community




                                                • Desk Community Learning Series


                                                • Digest


                                                • Functions


                                                • Meetups


                                                • Kbase


                                                • Resources


                                                • Glossary


                                                • Desk Marketplace


                                                • MVP Corner


                                                • Word of the Day


                                                • Ask the Experts





                                                          Manage your brands on social media



                                                                Zoho TeamInbox Resources



                                                                    Zoho CRM Plus Resources

                                                                      Zoho Books Resources


                                                                        Zoho Subscriptions Resources

                                                                          Zoho Projects Resources


                                                                            Zoho Sprints Resources


                                                                              Qntrl Resources


                                                                                Zoho Creator Resources



                                                                                    Zoho CRM Resources

                                                                                    • CRM Community Learning Series

                                                                                      CRM Community Learning Series


                                                                                    • Kaizen

                                                                                      Kaizen

                                                                                    • Functions

                                                                                      Functions

                                                                                    • Meetups

                                                                                      Meetups

                                                                                    • Kbase

                                                                                      Kbase

                                                                                    • Resources

                                                                                      Resources

                                                                                    • Digest

                                                                                      Digest

                                                                                    • CRM Marketplace

                                                                                      CRM Marketplace

                                                                                    • MVP Corner

                                                                                      MVP Corner







                                                                                        Design. Discuss. Deliver.

                                                                                        Create visually engaging stories with Zoho Show.

                                                                                        Get Started Now


                                                                                          Zoho Show Resources

                                                                                            Zoho Writer

                                                                                            Get Started. Write Away!

                                                                                            Writer is a powerful online word processor, designed for collaborative work.

                                                                                              Zoho CRM コンテンツ






                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方