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 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.remove(v_Random);
        v_OutputListSize = v_OutputListSize - 1;
    }
    l_Output = l_OutputShuffled.subList(0,v_StrLength);
    v_Output= l_Output.toString().replaceAll(",","");
    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.remove(v_Random)
  17.          v_OutputListSize = v_OutputListSize - 1
  18.      } 
  19.      l_Output = l_OutputShuffled.subList(0,v_StrLength)
  20.      v_Output= l_Output.toString().replaceAll(",","")
  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().replaceAll(",","");
    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().replaceAll(",","")
  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().replaceAll(",","");
    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().replaceAll(",","")
  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: 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.