Trying to make zoho invoice have a button

Trying to make zoho invoice have a button

Hello

I am getting this error with the code below. Anyone know how to fix?

  • Check and update the code in line 5 as there is a Exception : Variable 'invoice_id' is not defined

// Define Organization ID (Replace with your actual Zoho Invoice organization ID)
organizationID = "YOUR_ORG_ID"; // Replace with your Zoho Invoice organization ID

// Ensure invoice_id is passed correctly
if(input.invoice_id == null || input.invoice_id == "")
{
    return "Error: Invoice ID is missing.";
}

invoiceID = input.invoice_id.toString(); // Assigning the invoice ID from input

// Fetch Invoice details
invoiceDetails = zoho.invoice.getRecordById("Invoices", invoiceID, organizationID);

// Check if invoice details are retrieved successfully
if(invoiceDetails.contains("code") && invoiceDetails.get("code") != 0)
{
    return "Error retrieving invoice: " + invoiceDetails.get("message");
}

// Get Customer Email
customerEmail = invoiceDetails.get("customer_email");

// Ensure the email is available
if(customerEmail == null || customerEmail == "")
{
    return "Error: Customer email is missing for invoice " + invoiceID;
}

// Define recipient details
recipientMap = Map();
recipientMap.put("email", customerEmail);
recipientMap.put("action_type", "SIGNER");

// Define document details
documentMap = Map();
documentMap.put("template_id", "Agreement_Template_ID");  // Replace with actual template ID
documentMap.put("recipients", list(recipientMap));

// Send agreement for signature
signDocResponse = zoho.sign.createDocument(documentMap);

// Log response and add a note in invoice
if(signDocResponse.get("status") == "success")
{
    note = "Agreement sent for signature via Zoho Sign.";
    zoho.invoice.addNote("Invoices", invoiceID, note, organizationID);
    return "Agreement successfully sent for signature.";
}
else
{
    note = "Error in sending agreement: " + signDocResponse.toString();
    zoho.invoice.addNote("Invoices", invoiceID, note, organizationID);
    return note;
}