Knowledge Base - Detailed Examples

How to fetch Invoices and their Products to populate them in a Zoho Creator Form

Lets assume we have a Zoho Creator Form with the following fields:

  • Subject (Single Line field type)
  • Invoice Date (Date field type)
  • Invoice Number (Number field type)
  • Product Name (Single Line field type)
  • Quantity (Number field type)
  • Unit Price (Currency field type)

To fetch records from Invoices module and populate them in Form fields add the following script in the required Form Actions block:

InvoiceList=zoho.crm.getRecords("Invoices");
for each InvoiceRecord in InvoiceList
{

//To get Invoice Details
Subject=InvoiceRecord.get("Subject");
Invoice_Date=InvoiceRecord.get("Invoice Date");
Invoice_Number=InvoiceRecord.get("Invoice Number");

//To get Products linked to this Invoice
productList=InvoiceRecord.get("product").toJsonList();
for eachProductRecordinproductList
{
ProductMap=ProductRecord.toMap();
Product_Name=ProductMap.get("Product Name");
Quantity=ProductMap.get("Quantity");
Unit_Price=ProductMap.get("Unit Price");
}
}

where,

InvoiceList

is the response returned asmapby Zoho CRM which holds the records fetched from Zoho CRM’s Invoices module. Check sample response here.

Invoices

refers to the Invoices module, ofstringdatatype in Zoho CRM.

InvoiceRecord

stands for each unique record fetched from Zoho CRM's Invoices module

Subject
Invoice_Date
Invoice_Number
Product_Name
Quantity
Unit_Price

are Zoho Creator Form fields

"Subject"
"Invoice Date"
"Invoice Number"
"product"

are Zoho CRM field label names, ofstringdatatype.

productList

holds the Products(for each Invoice record) inlistformat.

ProductRecord

stands for each unique record in productList


ProductMap

holds each unique record in productList in map format


Share this post : FacebookTwitter