Transfer subform data using functions

Transfer deal subform data from your CRM to a third-party application using a custom function whenever a new deal is created.

Many businesses—particularly those in wholesale, distribution, or manufacturing—consider deals to be the equivalent of sales orders or job cards. They typically use an in-house ERP system to fulfill these orders, which involves tracking inventory, managing logistics, handling billing, and other related tasks. These businesses often utilize webhooks to transfer deal information from their CRMs to the ERP systems.

However, a cursory look at your CRM reveals that webhooks have a limitation: They can't fetch and send subform data due to their complex structure. For example, if you have product information like product names, colors, quantities, and prices stored in deal subforms, you can't transfer it to your ERP system. This limitation can disrupt business operations, forcing users to update data manually, which in turn decreases productivity. Our low-code tools are handy in scenarios like this.

A custom function can help you retrieve data from a deal's subform, as well as data from other related modules. This function then combines this data into a JSON payload and sends it to the ERP system using the invokeUrl task. To achieve this, create a workflow rule for the Deals module that triggers the function whenever a new deal is created. Read on to learn more.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a custom service and establish a connection between your Zoho CRM account and the ERP system, as detailed in the "Create Connection" section below. Learn more
  • Create a workflow rule for the Deals module that triggers every time a deal is created in your CRM. Learn more
  • Write a custom Deluge function that pushes the deal's subform data to the ERP system and link it up with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a connection

The first step is to create a custom connection between your Zoho CRM account and the third-party ERP system.

  1. Navigate to Setup > Developer Space > Connections.
  2. Click Create Connection.
  3. In the Pick Your Service tab, verify whether the ERP software is available as an out-of-the-box connection.
  4. Otherwise, navigate to the Custom Services tab and click Create New Service.
  5. On the Create Service page, do the following:
    1. Service Name: Enter the name of the ERP system you're connecting to (e.g. Epicor ERP, Sage X3).
    2. Service Link Name: Specify the name of the service without spaces (e.g. epicor_erp, sage).
    3. Authentication Type: Select the appropriate option according to your requirements.
    4. Enter the required details according to the authentication type you've chosen.
    5. Click Create Service and then click Create Connection.
  6. On the Create Connection page, do the following:
    1. Connection Name: Enter the name of the connection. If you're setting up multiple connections for one service, use a unique name for each connection instead of using the service's default name.
    2. Connection Link Name: Customize the name of the connection, if required.
    3. Select Create and Connect.
    4. Follow the authorization prompts from your service per the authentication type.
  7. Once the connection is created, you'll see an invokeUrl statement for Deluge that you can use to build your function.

Create a workflow rule

The next step is to create a workflow rule linked to a custom function.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select the Module as Deals from the dropdown list.
  3. Provide a name for the rule. For example: "Transfer subform data using function".
  4. Add a description, if required, then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Create from the dropdown.
    2. Click Next.
  6. In the Which deals would you like to apply the rule to? section, select All Deals, then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name for the function, as well as a description, if necessary.
  9. In the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Deals - Deal Id, name it Id, and click Save.
    4. Click Save & Execute script.
  10. Click Save on the workflow rule page.

The code

Code Copied
// Fetch the deal record
resp = zoho.crm.getRecordById("Deals",Id);
// Extract the subform data
subform = ifnull(resp.get("Product_Details"),"");
subformList = List();
// Loop through each subform entry
for each rec in subform
{
	product = ifnull(rec.get("Product_Name"),"");
	product_id = ifnull(rec.get("Product_Name"),"").get("id");
	color = ifnull(rec.get("Color"),"");
	pcs = ifnull(rec.get("Pcs"),"");
	price = ifnull(rec.get("Price"),"");
	subformMap = Map();
	subformMap.put("product",product);
	subformMap.put("product_id",product_id);
	subformMap.put("color",color);
	subformMap.put("pcs",pcs);
	subformMap.put("price",price);
	subformList.add(subformMap);
}
mp = Map();
mp.put("Product_Data",subformList);
// Send to ERP system using invokeUrl
response = invokeurl
[
	url :"URL of the third party application"
	type :POST
	parameters:mp
	connection:"connectionname"
];
// Log response
info "response : " + response;

Notes

  • Add the subform and its corresponding fields to the deals layout; for example, Product Name, Color, Pcs, and Price.
  • Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
  • Enter the API Endpoint URL of the third-party application in the code snippet.
  • Make sure to use the accurate API names for their corresponding fields (e.g., "Product Name") in the code snippet. Learn more
  • This is a sample function that needs customization for specific third-party applications, where data needs to be transferred.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to Deals > + Create Deal.
  2. On the Deal Details page, enter the deal information, including the fields in the subform, and then click Save.
    The workflow rule will be triggered.
  3. Check whether the ERP system accurately reflects the subform data from the deal.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleDeals
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityHigh
  • Implementation Time60 minutes

Features used in the solution

ConnectionWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!