Troubleshooting in Creator #3: Deluge execution limit optimization

Troubleshooting in Creator #3: Deluge execution limit optimization



Dear developers,

A Deluge statement execution corresponds to each line of code executed within a certain script. The total number of lines executed to complete a certain task on an action like on success is associated with a Deluge execution limit in Creator. To ensure good performance and usability, the number of lines of code executed at a time should be optimized.

Apart from each line of code written under an action, Deluge executions depends on factors such as the use of certain tasks, loops, and functions.

For example, if you're running a for each statement for a form which has 100 records in it, and you have 5 lines of code within the for each, the total number of Deluge statements executed will be 500.

If you have a function call inside the workflow, the number of lines of code in the function will also add up to the Deluge execution limit.

In this post, we'll discuss some simple scripting practices and ways to optimize code executions in Deluge:

Case 1: Using for each tasks
Case 2: Reducing variable definition to store fetched data
Case 3: Avoiding multiple IF statements and using ELSE IF
Case 4: Using built-in functions instead of counter variables



Ways to optimize execution

Case 1: Using for each task

While using for each tasks, we can utilize criteria to control the records through which it iterates.

Example:
  1. for each rec in Form_Name[ID!=0 ] // this will iterate all the records in the form
  2. {
  3. ....
  4. }

Instead, try the below script:

  1. for each rec in Form_Name[field_name=value && field_name2=value2] // this will only be executed for records that satisfy the given criteria
  2. {
  3. ....
  4. }

To iterate through records within a specified range, which meet a criteria, follow the below syntax:
  1. for each rec in Form_Name[<criteria>] range from <start_index> to <end_index>;


Case 2: Reducing variable definition to store fetched data

In some cases, we assign fetched values to a variable and use that variable within the script. If this assignment is done within a for each task, it can increase the Deluge execution. Therefore, instead of this assignment, we can directly use the fetched data in the workflow.

For example:

  1. fet=form[criteria];
  2. a=fet.field1;
  3. b=fet.field2;
  4. input.total=a+b;

Instead, try:

  1. fet=form[criteria];
  2. input.total=fet.field1+fet.field2;




Case 3: Avoiding multiple IF statements and using ELSE IF

When you need to execute a task based on multiple conditional statements, using else if statements can help avoid extra lines of code execution.


For example:

  1. if(a==1)
  2. {
  3. ...
  4. ....
  5. }
  6. if(a==2)
  7. {
  8. ..
  9. ...
  10. }
  11. if(a==3)
  12. {
  13. ..
  14. ...
  15. }

Instead, use:

  1. if(a==1)
  2. {
  3. ..
  4. ...
  5. }
  6. else if(a==2)
  7. {
  8. ..
  9. }
  10. else
  11. {
  12. ..
  13. ...
  14. }


Case 4: Using built-in functions instead of counter variables

Suppose we need to get a sum/count of data for a particular field for a set of records. It's usually done by using a counter variable, as shown below:

  1. ctr=0;
  2. for each rec in Form_name[criteria]
  3. {
  4. ctr=ctr+1;
  5. }
  6. info ctr;


Instead of the above script, we can use our built-in function, count(), as shown below:
  1. 1.fet=form_name[criteria].count(ID);info fet;


Note: The count function in the aggregate records Deluge task returns the count of values (including empty strings) a specified field holds, from records fetched using a criteria.

Now imagine we have to use the record count inside an if statement to execute a particular task, then usually the script used would look something like this:

  1. var=Formname[x=y && z=t];
  2. Var2=var.count(ID);
  3. if(var2>0)
  4. {
  5. ..
  6. ...
  7. }

This can be optimized to:

  1. If (Formname[x=y && z=t].count(ID)>0)
  2. {
  3. ..
  4. ...
  5. }

And we hope that helped! You can find more information about our built-in functions in this help article.


Please let us know how you like this article in the comments below, as well as any other topics you'd like to see us work on. Contact support@zohocreator.com for any further questions.





                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources



                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources


                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources


                                                            Zoho Sprints Resources


                                                              Qntrl Resources


                                                                Zoho Creator Resources


                                                                  Zoho WorkDrive Resources



                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series


                                                                      • Tips

                                                                        Tips

                                                                      • 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