Configuring a Scheduler

Configuring a Scheduler

Feature Availability

Configuring a Scheduler 

A scheduler is triggered at the specified time to complete the defined action. The action to be performed is written as a custom function using Deluge scripts in the scheduler handler. The following attributes are passed to the custom function when the scheduler is triggered: Name 
 
Name
Data Type
Description 
Network 
Map
The details of your network
User
Map
Details of the configuration owner. 
 
Let's consider a scheduler that collects the list of tasks you are assigned to for the day, from Zoho Connect and shares through a bot in Cliq. This scheduler is executed daily (Monday to Friday) at 10 AM to track the task list for the day. First, create the scheduler by giving the name, description followed by the recurring period and the time of execution. 
 
The sample code for this example case is as follows:  
  1. returnMap = Map();

    scopeId = network.get("id");//Network id on which the scheduler getting executed

    //zohoconnectoauth authtentication to fetch data from Zoho Connect

    response = invokeurl

    [

     url :"https://connect.zoho.com/pulse/api/tasks"

     type :GET

     parameters:{"dates":"today","scopeID":scopeId}

     connection:"zohoconnectoauth"

    ];

    info response;

    if(response.containKey("result") && response.get("result") == "failure")

    {

     returnMap.put("status","failure");

    }

    else

    {

     tasks = response.get("tasks").get("tasks");

     formatedDate = response.get("tasks").get("todayFormattedDate");

     rows = list();

     for each task in tasks

        {

      row = map();

      row.put("Title", task.get("title"));

      row.put("Section", "["+task.get("section").get("name")+"] ("+task.get("section").get("url")+")");

      row.put("Board", task.get("partition").get("name"));

      row.put("Status", task.get("taskStatus").get("name"));

      row.put("Priority", task.get("taskPriority").get("name"));

      rows.add(row);

        }

    //Use a message format that is compatible with Cliq

     content = "Task to be completed by "+formatedDate+".";

     message = {"text":content,"card":{"title":"Today's task", "thumbnail":"https://play-lh.googleusercontent.com/_g", "theme":"modern-inline"},"slides":[{"type":"table", "title":"Tasks", "data":{"headers":["Title","Section","Board","Status", "Priority"],"rows":rows}}]};

    info message;

    //post message on the Cliq bot using `zohocliqoauth` `

     

Trail Run

Once the scheduler is created, click the Save & Execute option found in the top-right corner of the code editor to know if the scheduler is working as intended. 
 
In certain cases, the execution of the scheduler may be marked as a 'success' even if the scheduled action is not complete. In the example case given above, the invoking of Zoho Cliq API from the function may have failed because of invalid authentication or a bad request, and the message will not be posted in the bot. However, in the logs, the result is given as 'success'. Therefore, to avoid such discrepancies, the return value of the custom function should be based on the status of the action performed.  

  1. cliqResponse=zoho.cliq.postToBot ("A new task",message, "zohocliqoauth");

    if(cliqResponse == null || cliqResponse.containKey("status") == false || cliqResponse.get("status") != "success")

    {

    returnMap.put("status","failure");

    }


In the above sample code, the scheduler execution is logged as 'success' only when the message is shared in Cliq. 

Execution Failure

If there is a failure in the scheduler execution, the configuration owner will be notified about the failure. They can access the logs and manually run the scheduler if the failure is due to errors in script, connection, or authentication until they resolve the issue. However, if there are 100 continuous failed attempts, the configuration will be automatically disabled. 
 
If you have any questions regarding schedulers, please reach out to us at support@zohoconnect.com.