Search code examples
zohozoho-deluge

How to import a list into an email with Zoho Deluge?


I was recently tasked with learning the Zoho scripting language Deluge for a project.

That project is essentially to take a list of the tickets that come through Zoho Desk based on priority/shift times and sort them by ones that are unassigned, and then taking that list to send out as an email to inform the team of what needs to be taken.

My issue stems from actually getting the list to be pulled into the email body. When I do the list on its own I'm able to pull the info, and I'm also able to send the emails on their own, but when I end up combining them it always seems to tell me there's an error with the overall script.

Here's the script I have so far:

url = ".../api/v3/requests/";
headers = {"authtoken":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"};

first_shift_starts_at = (zoho.currentdate + ' ' + '08:00:00').toDateTime();
first_shift_ends_at = (zoho.currentdate + ' ' + '16:00:00').toDateTime();
is_first_shift = zoho.currenttime > first_shift_starts_at && zoho.currenttime < first_shift_ends_at;

second_shift_starts_at = (zoho.currentdate + ' ' + '17:00:00').toDateTime();
second_shift_ends_at = (zoho.currentdate + ' ' + '22:00:00').toDateTime();
is_second_shift = zoho.currenttime > second_shift_starts_at && zoho.currenttime < second_shift_ends_at;

third_shift_starts_at = (zoho.currentdate + ' ' + '23:00:00').toDateTime();
third_shift_ends_at = (zoho.currentdate + ' ' + '07:00:00').toDateTime();
is_third_shift = zoho.currenttime > third_shift_starts_at && zoho.currenttime < third_shift_ends_at;

if(is_first_shift=="Result": "success")
{
input_data = {
        "list_info": {
            "row_count": 250,
            "start_index": 1,
            "sort_field": "id",
            "sort_order": "asc",
            "get_total_count": true,
            "search_fields": {
                        "priority.name": "1st Shift",
                    "status.name": "Open",
                    "technician": "null"
                     }
                 }
              };
}
else if (is_second_shift=="Result": "success")
{
input_data = {
        "list_info": {
            "row_count": 250,
            "start_index": 1,
            "sort_field": "id",
            "sort_order": "asc",
            "get_total_count": true,
            "search_fields": {
                        "priority.name": "2nd Shift",
                    "status.name": "Open",
                    "technician": "null"
                     }
                 }
              };
}
else (is_third_shift=="Result": "success")
{
input_data = {
        "list_info": {
            "row_count": 250,
            "start_index": 1,
            "sort_field": "id",
            "sort_order": "asc",
            "get_total_count": true,
            "search_fields": {
                        "priority.name": "2nd Shift",
                    "status.name": "Open",
                    "technician": "null"
                     }
                 }
              };
};

params = {"input_data": input_data};
response = invokeurl
[
    url: url
    type: POST 
    parameters: params
    headers: headers
];
info response;

emailSubject = "Unassigned Tickets";
emailBody = "These tickets are currently unassgined in the queue" + input_data "please make sure they are taken ASAP!";

sendmail
[
    from: <from_address>
    to:  <to_address>
    subject: emailSubject
    message: emailBody
]


returnObj = Collection();
returnObj.insert("result":"success");
returnObj.insert("message": "Update Notification Mail sent successfully");
return returnObj;   

Any help is very much appreciated!


Solution

  • This line looks like it is missing a needed + concatenation operator:

    emailBody = "These tickets are currently unassgined in the queue" + input_data "please make sure they are taken ASAP!";
    

    Try changing it to (notice the additional + after input_data):

    emailBody = "These tickets are currently unassigned in the queue" + input_data + "please make sure they are taken ASAP!";
    

    Also, it might be good to display the contents of emailBody to make sure it is the expected contents before sending it. Add the following after emailBody is assigned:

    info emailBody;

    05-21-2023 Update:

    Notes regarding "Error in if(is_first_shift=="Result": "success")":

    Yes, sometimes Zoho-Deluge will report an error that happens on some line within an if block as being an error on the if line.

    Re-reading the code, it looks like you made a correct change from if(is_first_shift=="Result": "success")
    to if(is_first_shift == true)

    If you haven't already make that same type of change for the lines: else if (is_second_shift=="Result": "success")
    and
    else (is_third_shift=="Result": "success")

    That should resolve the error.

    05-30-2023 Update:

    If the 05-21-2023 Update doesn't resolve the error then it might be necessary to fall back to some debugging to help identify where the error is occurring. This is because sometimes Zoho-Deluge leans toward being very general in error messages. Try the following and see if they help:

    • Using Deluge's info command display each of is_first_shift, is_second_shift, and is_third_shift and make sure they have the values you expect.
      Example code:
      info "is_first_shift: [" + is_first_shift + "]";

    • Try to identify how far the script gets before hitting the error. For example does the script display the results of info emailBody; or does it fail before then?