Default field that is present when searching Zoho Invoices is not present when pulling an invoice directly using ID
So when I just pull a list of all records, lets say from the past 7 days. It lists the records in a JSON as expected with data for each. One of the fields listed is "transaction_type". This is generally "renewal", "new", etc. The problem is, when I use "getRecords" this field is available but if I use "getRecordsByID" it is not. It should be right below the "invoice_url" key within the data but it is just not present for "getRecordsByID".
I created a function so you can test what I'm talking about. This is intended to be run as a function within CRM. Note: It needs a connection to books to work and an invoice number to test with.
//Ignore, formatting variable
newLine = "..................................................";
// TEST VARIABLES: Change these to your orgID and a selected invoice number to use to test
/*
orgID - Should be the Orginization ID pulled from Books (NOT CRM).
When looking at the url for books it is: https://books.zoho.com/app/53XXXXXX#/
The 53XXXXXX is the number you want (no #)
selectedInvoiceNumber - This is the invoice number.
It should look something like this: INV-672689
Note: Don't forget to change the oauth connection name as well (CHANGE_ME_BOOKS_CONNECTION)
This would be the "Connection Link Name" found when going to:
CRM settings -> Developer Hub -> Connections -> My Connections
You will need a books connection. Just give it all scopes for testing and remove it later.
This script only reads data it does not write anything.
*/
orgID = "CHANGE_ME";
selectedInvoiceNumber = "CHANGE_ME";
// Search parameter to get active invoices
searchParams = {"invoice_number":selectedInvoiceNumber};
// Step 1: Get the test invoice via getRecords:
response = zoho.books.getRecords("Invoices",orgID,searchParams,"CHANGE_ME_BOOKS_CONNECTION");
if(response.size() > 0 && response.get("invoices").size() > 0)
{
selectedInvoice = response.get("invoices").get(0);
// Debug: Print the invoice data, uncomment to debug
//info selectedInvoice;
invoiceID = selectedInvoice.get("invoice_id").toString();
transactionType1 = selectedInvoice.get("transaction_type").toString();
// Step 2: Retrieve the same invoice using getRecordsByID:
selectedInvoice2 = zoho.books.getRecordsByID("Invoices",orgID,invoiceID,"CHANGE_ME_BOOKS_CONNECTION");
// Debug: Print the invoice data, uncomment to debug
//info selectedInvoice2;
transactionType2 = selectedInvoice2.get("transaction_type").toString();
// Step 3: Print both transaction types
return "getRecords: " + transactionType1 + " " + newLine
+ " " + "getRecordsById: " + transactionType2;
}
else
{
return "No invoice found with the specified number";
}
Please advise! The key "transaction_type" is incredibly helpful to use when determining transactions for clients programmatically and currently I am forced to search for the transaction with "getRecords" using the ID, then copy that "transaction_type" and then use it. It should 100% just be available within the normal "getRecordsByID" module right?
Thanks!