Invoice to Serialized Equipment

Difficulty: Intermediate
Estimated reading time: 5 mins
Estimated implementation time: 1 hour

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 :"" + customerNameEncoded + ")"
	type :GET
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
			equipmentMap = {"Name":itemName + " | " + crmAccountName,"Associated_Account":crmAccountId,"Product_Name":itemName,"Serial_Number":serialNumber,"SKU":sku,"Invoice_Number":invoiceNumber,"Invoice_URL":"" + invoiceId,"Status":"Active"};
			createEquipment = zoho.crm.createRecord("Equipment", equipmentMap);
		// Equipment Record Already Exists
			info "Equipment record with serial number " + serialNumber + " already found.";

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

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

More Free Resources

Deluge Tips – Null Check

When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.

Read More »