Call Id Generation Documentation

automation.CreateIssue()

This document breaks down and explains the key functions and workflows from a Deluge script used in Zoho CRM to handle service ticket creation and communication with an ERP system.


📌 Main Functions Breakdown

1. 🔹 Ticket ID Generation

function generateTicketID(ticketType, count) {
    date = today.toString("yyMMdd");
    prefix = "";

    if(ticketType == "Installation Supervision Call" || ticketType == "Paid Installation" ||
       ticketType == "Installation call" || ticketType == "Post Installation Visit" ||
       ticketType == "Pre Installation Visit") {
        prefix = "I";
    }
    else if(ticketType == "Dealer Display Call" || ticketType == "Dealer Stock Call") {
        prefix = "D";
    }
    else if(ticketType == "Repair Call") {
        prefix = "C";
    }
    else if(ticketType == "AMC Visit") {
        prefix = "M";
    }
    else if(ticketType == "Warehouse Stock") {
        prefix = "W";
    }

    paddedCount = count.toString().padStart(5, "0");
    return prefix + date + paddedCount;
}

2. 🔎 Technician Assignment

function findTechnician(state, city, area, brand) {
    area_filter = "equals";
    city_filter = "equals";

    if(area.contains("(")) {
        area = area.replaceAll("(", "\\(").replaceAll(")", "\\)");
        area_filter = "starts_with";
    }
    if(city.contains("(")) {
        city = city.replaceAll("(", "\\(").replaceAll(")", "\\)");
        city_filter = "starts_with";
    }

    query_url = `(((State:equals:${state}) and(City:${city_filter}:${city}))and(Name:${area_filter}:${area}))and(Brand:equals:${brand})`;

    for(page in 1..10) {
        searchResults = zoho.crm.searchRecords("Pincode", query_url, page, 200);
        if(searchResults.isEmpty()) break;
        if(searchResults.get(0).get("Technician") != null) {
            return searchResults.get(0);
        }
    }
    return null;
}

3. 📢 Customer Notification

function notifyCustomer(phone, brand, ticketId, technicianName, technicianPhone) {
    try {
        message = { ... }; // WABA message body
        response = invokeurl[...];

        if(response.get("statusCode") != 200) {
            smsMessage = `Thanks for calling ${brand}. Your service call has been registered vide ${ticketId}...`;
            invokeurl[...]; // Fallback SMS
        }
    } catch (e) {
        logError("Customer Notification Failed", e.toString(), ticketId);
    }
}

4. ⚙️ ERP Ticket Creation

function createERPTicket(ticketData) {
    try {
        response = invokeurl[...]; // POST to ERP API
        return response;
    } catch (e) {
        logError("ERP Ticket Creation Failed", e.toString(), ticketData.get("id"));
        return null;
    }
}

5. ⚠️ Error Logging

function logError(errorName, module, recordId, description, user) {
    errorData = {
        "Name": errorName,
        "Module": module,
        "Module_Record_ID": recordId.toString(),
        "Error_Description": description,
        "Status": "Open",
        "Logged_In_User": user ? user : zoho.loginuser
    };
    zoho.crm.createRecord("Error_Logs", errorData, {"trigger":{"workflow"}});
}

✅ Main Workflow Documentation

🌐 Purpose

Handles: - Ticket ID generation
- Technician assignment
- Ticket creation in ERP
- Customer notifications
- CRM error logging


🤔 Key Business Logic

Ticket ID Prefixes:

  • InstallationI
  • DealerD
  • RepairC
  • AMCM
  • WarehouseW

Technician Assignment Logic:

  • Based on state, city, area, brand
  • Handles special characters
  • Paginates for large datasets

Notification System:

  • WABA (WhatsApp Business API) integration
  • Fallback SMS support with ticket details

ERP Integration:

  • REST API with token
  • Maps ticket fields to ERP system

⚡ Error Handling

  • All core actions wrapped in try-catch
  • Logs to CRM's Error_Logs module
  • Captures detailed context for debugging

📅 Prerequisites

  • Valid WABA/SMS API credentials
  • ERP API token
  • Custom CRM Modules:
    • Leads
    • Contacts
    • Pincode
    • Error_Logs
    • Technicians

On this page