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 Deluge - Generate 5 Letter Booking Retrieval Code

What?
This is a quick article on how to generate a 5 letter code from several functions: one which returns 5 randomly selected characters and another two which convert a number to 5 letters.

Why?
Zoho doesn't have a function to generate random numbers or strings. There are workarounds however.

How?
The first note is that there is something that can emulate a random number... well it's not really random, it involves getting the milliseconds from a time object.
copyraw
v_Uid = zoho.currenttime.toLong();
     // returns something like 1557400230165
  1.  v_Uid = zoho.currenttime.toLong()
  2.       // returns something like 1557400230165 

Method #1: 5 Randomly Selected Letters

Using a snippet from the community forums on how someone shuffled a pack of cards, I came up with a function that will take a list of letters, shuffle the list, and return the first 5 characters.
copyraw
string generateRetrievalCode()
{
    // init
    v_Output = "";
    l_Output = List:String();
    l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    v_StrLength = 5;

    // everyday I'm shufflin
    l_OutputShuffled = List();
    v_OutputListSize = l_Alphabet.size();
    for each v_Element in l_Alphabet
    {
        v_Random = (zoho.currenttime.toLong()  %  v_OutputListSize);
        l_OutputShuffled.add(l_Alphabet.get(v_Random));
        l_Alphabet.removeElement(v_Random);
        v_OutputListSize = v_OutputListSize - 1;
    }
    l_Output = l_OutputShuffled.subList(0,v_StrLength);
    v_Output= l_Output.toString("");
    return v_Output;
}
  1.  string generateRetrievalCode() 
  2.  { 
  3.      // init 
  4.      v_Output = ""
  5.      l_Output = List:String()
  6.      l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
  7.      v_StrLength = 5
  8.   
  9.      // everyday I'm shufflin 
  10.      l_OutputShuffled = List()
  11.      v_OutputListSize = l_Alphabet.size()
  12.      for each v_Element in l_Alphabet 
  13.      { 
  14.          v_Random = (zoho.currenttime.toLong()  %  v_OutputListSize)
  15.          l_OutputShuffled.add(l_Alphabet.get(v_Random))
  16.          l_Alphabet.removeElement(v_Random)
  17.          v_OutputListSize = v_OutputListSize - 1
  18.      } 
  19.      l_Output = l_OutputShuffled.subList(0,v_StrLength)
  20.      v_Output= l_Output.toString("")
  21.      return v_Output; 
  22.  } 
This is my preferred method and it will return a string of 5 random uppercase letters.

Method #2: Convert time to letters
I've previously used substring to extract the milliseconds into 5 numbers and get the remainder from dividing it by 26 (modulus)... This is NOT to be used for Booking Retrieval Codes as it is easy to determine what code if you have the date/time of the booking as well as the customer's surname (method #1 would not be guessed by date/time):
copyraw
string generateRetrievalCode()
{
    // init
    v_Output = "";
    l_Output = List:String();
    l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    v_StrLength = 5;

    // convert milliseconds into 5 parts
     v_Uid = zoho.currenttime.toLong();
     v_UidStr = v_Uid.toString().trim();
     l_Parts.add( v_UidStr.substring(0,3) );
     l_Parts.add( v_UidStr.substring(3,6) );
     l_Parts.add( v_UidStr.substring(6,8) );
     l_Parts.add( v_UidStr.substring(8,10) );
     l_Parts.add( v_UidStr.substring(10,12) );

    // loop through parts
    for each v_Element in l_Parts
    {
        v_Remainder = v_Element.toLong() % 26;
        l_Output.add( l_Alphabet.get( v_Remainder ) );
    }

    // output
    v_Output= l_Output.toString("");
    return v_Output;
}
  1.  string generateRetrievalCode() 
  2.  { 
  3.      // init 
  4.      v_Output = ""
  5.      l_Output = List:String()
  6.      l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
  7.      v_StrLength = 5
  8.   
  9.      // convert milliseconds into 5 parts 
  10.       v_Uid = zoho.currenttime.toLong()
  11.       v_UidStr = v_Uid.toString().trim()
  12.       l_Parts.add( v_UidStr.substring(0,3) )
  13.       l_Parts.add( v_UidStr.substring(3,6) )
  14.       l_Parts.add( v_UidStr.substring(6,8) )
  15.       l_Parts.add( v_UidStr.substring(8,10) )
  16.       l_Parts.add( v_UidStr.substring(10,12) )
  17.   
  18.      // loop through parts 
  19.      for each v_Element in l_Parts 
  20.      { 
  21.          v_Remainder = v_Element.toLong() % 26
  22.          l_Output.add( l_Alphabet.get( v_Remainder ) )
  23.      } 
  24.   
  25.      // output 
  26.      v_Output= l_Output.toString("")
  27.      return v_Output; 
  28.  } 

Method #3: randomNumber() function
Using the randomNumber() function we can hope this works reliably:
copyraw
string generateRetrievalCode()
{
    // init
    v_Output = "";
    l_Output = List;
    l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    l_StrLength = {0,1,2,3,4};

    // assign a letter to a list entry
    for each index  v_Index in l_StrLength
    {
        l_Output.add( l_Alphabet.get(randomNumber(0, 25)) );
    }

    // output
    v_Output= l_Output.toString("");
    return v_Output;
}
  1.  string generateRetrievalCode() 
  2.  { 
  3.      // init 
  4.      v_Output = ""
  5.      l_Output = List; 
  6.      l_Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
  7.      l_StrLength = {0,1,2,3,4}
  8.   
  9.      // assign a letter to a list entry 
  10.      for each index  v_Index in l_StrLength 
  11.      { 
  12.          l_Output.add( l_Alphabet.get(randomNumber(0, 25)) )
  13.      } 
  14.   
  15.      // output 
  16.      v_Output= l_Output.toString("")
  17.      return v_Output; 
  18.  } 

Additional Notes:
As this was for a client who arranged outdoor activities for kids, I need to add a filter which blocks out swear words and the such. Experimental - DO NOT USE:
copyraw
string generateRetrievalCode()
{
       // ... refer to above functions
}
string generateKidSafeRetrievalCode()
{
    // init
    v_Output = "";
    l_BadWords = {"My","Bad","Words"};
    l_TimesTried = {1,2,3,4,5};

    // loop through times you will chance it
    for each v_TimeTried in l_TimesTried
    {
         // init
         b_BadWordFound = false;

         // get attempt
         v_Output = thisapp.generateRetrievalCode();

         // see if can use contains but check for word
         for each v_BadWord in l_BadWords
         {
              if(v_Output.indexOf( v_BadWord ) >= 0)
              {
                   b_BadWordFound = true;
              }
         }

         // if not found
         if(!b_BadWordFound)
         {
              break;
         }
    }

    // output
    return v_Output;
}
  1.  string generateRetrievalCode() 
  2.  { 
  3.         // ... refer to above functions 
  4.  } 
  5.  string generateKidSafeRetrievalCode() 
  6.  { 
  7.      // init 
  8.      v_Output = ""
  9.      l_BadWords = {"My","Bad","Words"}
  10.      l_TimesTried = {1,2,3,4,5}
  11.   
  12.      // loop through times you will chance it 
  13.      for each v_TimeTried in l_TimesTried 
  14.      { 
  15.           // init 
  16.           b_BadWordFound = false
  17.   
  18.           // get attempt 
  19.           v_Output = thisapp.generateRetrievalCode()
  20.   
  21.           // see if can use contains but check for word 
  22.           for each v_BadWord in l_BadWords 
  23.           { 
  24.                if(v_Output.indexOf( v_BadWord ) >= 0) 
  25.                { 
  26.                     b_BadWordFound = true
  27.                } 
  28.           } 
  29.   
  30.           // if not found 
  31.           if(!b_BadWordFound) 
  32.           { 
  33.                break
  34.           } 
  35.      } 
  36.   
  37.      // output 
  38.      return v_Output; 
  39.  } 

Source(s):
Category: Zoho :: Article: 678

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.