2

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!

Wattson
  • 23
  • 3

1 Answers1

1

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?

ZohoCoder
  • 385
  • 5
  • 15
  • Thank you for the feedback! I realized I was missing that after I had posted this. I am being told the error is with this line `if(is_first_shift=="Result": "success")` where it says it's getting an Improper Statement Error which might be missing a `;` at the end, but I'm pretty sure that's not it, or an incomplete expression so I've tried converting it to `if (is_first_shift == true)` but this does not seem to resolve the error. From what I can tell with this there is no actual error so I'm unsure why I'm getting it to begin with. – Wattson May 21 '23 at 09:24
  • I've updated my answer based on your comments. It looks like you are on the right track to solving the issue. – ZohoCoder May 21 '23 at 19:49
  • Yeah I had already made the change to the other lines before replying here and was still getting the same error. – Wattson May 23 '23 at 11:34
  • Okay, Then maybe update the original questions with the updated lines so other readers see the most current version of your code. – ZohoCoder May 30 '23 at 17:35
  • I've added an update to my response with some analysis suggestions to help see where the error is occurring. See the 05-30-2023 Update section – ZohoCoder May 30 '23 at 17:44
  • 1
    Oh sorry forgot to come back here and edit my reply, I was able to figure out that the error was just some minor syntax/formatting within Zoho Desk. Thank you for all the help though, I really appreciate it! – Wattson May 31 '23 at 09:09