Invoice to Serialized Equipment

Invoice to Serialized Equipment

When an Invoice is submitted in Zoho Books, an Equipment record is created in Zoho CRM that tracks which specific units a customer owns.
				
					
// Get Invoice Information
invoiceNumber = invoice.get("invoice_number");
invoiceId = invoice.get("invoice_id");
customerName = invoice.get("customer_name");
// Get CRM Account ID
customerNameEncoded = zoho.encryption.urlEncode(customerName);
searchAccounts = invokeurl
[
	url :"https://www.zohoapis.com/crm/v2/Accounts/search?criteria=(Account_Name:equals:" + customerNameEncoded + ")"
	type :GET
	connection:"crm_modules_full"
];
crmAccount = searchAccounts.get("data").get(0);
crmAccountId = crmAccount.get("id");
crmAccountName = crmAccount.get("Account_Name");
// Process line items, serial numbers, and create Equipment records in Zoho CRM
lineItems = invoice.get("line_items");
// Iterate through line items to see if there are serial numbers attached
for each  lineItem in lineItems
{
	sku = lineItem.get("sku");
	itemName = lineItem.get("name");
	serialNumbers = lineItem.get("serial_numbers");
	// Iterate through specific serial numbers and check if Equipment record has been created
	for each  serialNumber in serialNumbers
	{
		// Search for existing Equipment record with matching serial number
		searchEquipment = zoho.crm.searchRecords("Equipment","(Serial_Number:equals:" + serialNumber + ")");
		// No existing equipment record
		if(searchEquipment.isEmpty())
		{
			equipmentMap = {"Name":itemName + " | " + crmAccountName,"Associated_Account":crmAccountId,"Product_Name":itemName,"Serial_Number":serialNumber,"SKU":sku,"Invoice_Number":invoiceNumber,"Invoice_URL":"https://books.zoho.com/app#/invoices/" + invoiceId,"Status":"Active"};
			createEquipment = zoho.crm.createRecord("Equipment", equipmentMap);
		}
		// Equipment Record Already Exists
		else
		{
			info "Equipment record with serial number " + serialNumber + " already found.";
		}
	}
}
				
			

Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.

Want to learn even more?
Sign up for one of our Zoho courses!

Want to learn how to create Invoice and collect payment from Zoho Creator?

Or learn how complex assignment rules config Via Zoho CRM modules works?

Want this functionality, but don't want to do it yourself?

Click here to speak to us!

Need help with your Zoho system?

Hire a full time Zoho System Admin from our poolof highly qualified program graduates!

Related Resources