Create and manage node.js functions | Zoho Creator Help

Create and manage node.js functions

A function is a set of statements that is invoked in an application to perform a certain action or yield a desired result based on the logic in the code. Node.js is a cross-platform, open-source JavaScript runtime environment. Introducing Node.js will enable your app to run in a single process, without creating a new thread for every request.
Create a new function using node.js

To create a new node.js function:

  1. Click on  Workflows  to navigate to your  Workflow Dashboard .

  2. Click  Functions  tab.

  3. Click  New Function  button.

  4. The create page will appear.

  5. Enter  Function Name . This serves as the identifier using which the function can be invoked. Specify a meaningful name for the function without any empty spaces.

  6. Select  Node.js  as Language for scripting the function.

  7. Specify the  Arguments .
  8. Click  Create Function  button. The builder will appear.
  9. Now, Add required node.js code to the function.

  10. The function will get listed under  Functions  in the workflow dashboard.

 

Note :

  • Namespace : Namespace for node.js function will be  Default Namespace .
  • Return Type : Return value of a node.js function will only be of  Collection data type .
  • Argument : Node.js functions accept only  string  values.
  • Node.js functions cannot be renamed after creation.
Arguments and parameters in node.js functions

Similar to deluge function, node.js also requires you to specify arguments based on which your function runs. An argument is the instance that is passed to the method on running a function. At the event of creating a node.js function, you can specify an argument. If you have the necessity to add more arguments to the same function at a later stage, you can access the  Function Properties  in the builder (click the  Settings  icon).

To run a program, you need to define parameters in node.js functions. A parameter is the variable assigned for the value of an argument. It serves as the container in which the argument value passed from deluge is received in a node.js function.

Sample function

This function is created to calculate average in node.js function and uses the values obtained to update records using deluge.


void gradeCalculator.avgCalculation()
{
avg = 0.0;
for each i in Student_Details [ ID != 0 ]
{
total = i.Grand_Total.toString();
count = i.Number_of_Subjects.toString();
avg = thisapp.calculatorFunction(total,count).get("output").toDecimal();
i.Average = avg ;
}
 


module.exports = async function( context, basicIO )
{
var total = parseInt(basicIO.getParameter("total"));
var count = parseInt(basicIO.getParameter("count"));
var nodeFile = require("average.js");
basicIO.write(nodeFile.calculateAvg(total, count));
}
 

this.calculateAvg = function (total, count)
{
return (total/count);
}
 

Note :

  • module.exports = async function( context, basicIO ) should not be removed. If removed, an execution error will occur.
Config.json and Library
  • config.json is a configuration file.
  • node_modules is the folder to which you can upload your node.js files. Right click on the folder to upload files.
Call a node.js function

To call a node.js function in a deluge script, you need to use the statement indicated in the image below. In this example, “thisapp.calculatorFunction(total,count);” refers to the node.js function, which contains the value as a collection.

Get Value
Assign variables to the parameters that you input to obtain the output. In the above mentioned example, the variables are Total (Grand Total) and Count (Number of Subjects). These two parameters will be obtained using the statement basicIO.getParameter statements. The node_modules folder serves as a container for you to upload .js format file that can be used in you node.js functions. You can create the code and save the code in this folder as well and access it from your node.js function. For instance, we have created the average.js file that has the code to calculate the average for the variables total and count. nodeFile = require(average.js) is the syntax used to access the .js file to complete calculation. But, the code for processing the variables to obtain the average can also be directly written in node.js script as well. The node_modules will be of use when you are creating complex calculations or ones that will be repetitively used.

The basicIO.write statement is used to print the result following calculation. The result obtained thus can be used in a deluge function for further processing.

Points to remember
  • .js files can only be uploaded to the node_modules.
  • The file upload limit of all the files put together is 10 MB.
  • The size of your request and response payload can only be up to 1 MB each.
  • The file size in the editor can only be up to 1 MB.
  • You can pass a maximum of 20 arguments to node.js functions.
  • You can call a function 5 times in one deluge script.
  • You need to receive a response within 40 seconds from the start of a function call, beyond which the execution will fail.
  • Following are the supported default node-modules:
    • Request-promise
    • bluebird
    • crypto
    • axiom
    • other default node packages (request, fs, url, etc.)
  • Currently this feature is not supported in DS files. The cloud functions will not be captured during import/export/backup/duplicate actions. Instead it will be substituted with an empty deluge function of same name to avoid errors.
  • console.log  statement will not work in creator cloud functions

    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION









                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Understand functions

                                                                                                                A function is a set of deluge or java statements grouped together, which can be invoked within an application whenever required. Use functions to structure deluge scripts in a modular way. Related functions can be grouped under a common category, ...
                                                                                                              • Create and manage Java functions

                                                                                                                A function is a set of statements that is invoked in an application to perform a certain action or yield a desired result based on the logic in the code. Java is a widely used programming language. Introducing Java will equip you to implement the ...
                                                                                                              • Create and Manage Extensions

                                                                                                                Build and Distribute Extension Extensions are the software components or add-ons that let you extend the functionalities of Zoho Creator. Learn more about extensions. Note: Currently, you can only build widgets as extensions in your Creator. Step 1: ...
                                                                                                              • Create new deluge function

                                                                                                                To create a new deluge function: Click on Workflows to navigate to your Workflow Dashboard. Click Functions tab. Click NewFunction button. The create page will appear. Enter FunctionName. This serves as the identifier using which the function can be ...
                                                                                                              • Create and Manage Batch Workflows

                                                                                                                1. What Does This Page Cover? Learn how you can efficiently split your larger tasks into smaller batches and process them at off-peak hours using batch workflows. Before you proceed to create a batch workflow, check this page to understand about ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources