Update date fields between modules

Auto-update date fields in related records of two modules with a business day offset.

Businesses often have a date field in one module that must be updated with the date from a related module. In addition, they expect this date field to reflect the actual date plus an additional two business days from the related module.

For example, consider a furniture business that builds custom chairs and tables and uses CRM to manage production and sales. The business tracks customer orders in the Deals module, while each piece of custom furniture is managed in the Products module. They want to add two business days to the completion date of a product and update it as the delivery date in the related deal record. This practice ensures they set realistic delivery expectations and deliveries occur only during business days. However, updating the delivery date of a deal from its related product can quickly become overwhelming and take up a lot of time. Luckily, there is a way to simplify this process.

All that's needed is to set up a workflow rule that triggers whenever the product's completion date is modified and then connect it to a custom function that automatically updates the delivery date in the deal records. For further details, refer to the sections below.

Permissions and availability

  • Users with the Modules Customization permission can add custom fields.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Add a Date field to the Products and Deals modules. The fields will hold the completion date and delivery date, respectively. Learn more
  • Add a Lookup field to the Deals module. The lookup establishes a relationship between the deal and the product.
  • Create a workflow rule for the Products module that triggers every time its completion date is modified. Learn more
  • Write a custom Deluge function that updates the deal's delivery date with a business day offset and link it with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Add custom fields

The first step is to add the custom date and lookup fields to the Deals module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Deals module to open the layout editor.
  3. Drag and drop the Lookup field from the New Fields tray to the desired section of the layout.
  4. Name the lookup field (e.g. "Select Product").
  5. Select the lookup module (e.g. "Products") from the dropdown menu.
  6. Enter the title (e.g. "Related Deal") for the related list in the lookup module, and click Done.
  7. Once you have finished, click Save and Close.
  8. Similarly, follow the above steps to add a Date field (e.g. "Completion Date") to the Products module.

Create a workflow rule

Create a workflow rule to update the delivery date in the Deal when the related Product's completion date is modified.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Products from the module dropdown list.
  3. Provide a name for the rule. For example: "Update delivery date from product".
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, and then select Edit from the dropdown.
    2. Choose Specific field(s) gets modified from the dropdown, then enter the condition "When <Completion Date> is modified to <any value>".
    3. Click Next.
  6. In the Which products would you like to apply the rule to? section, select All Products, 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 provided below.
    2. Click Edit Arguments.
    3. Choose Products - Product Id, then name it id.
    4. Click the + icon to add more arguments.
    5. Choose Products - Completion Date, name it date, then click Save.
    6. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
relrec = zoho.crm.getRelatedRecords("Related_Deal","Products",id);
if(relrec.size() > 0)
{
	for each  rec in relrec
	{
		update = zoho.crm.updateRecord("Deals",rec.get("id"),{"Delivery_Date":date.addBusinessDay(2).toString("yyyy-MM-dd")});
		info update;
	}
}

Notes

  • Make sure to use the accurate API names for their corresponding fields in the code snippet (e.g., Related Deal). Learn more
  • This function adds two business days to the product's completion date and updates the deal's delivery date. You can customize the number of days by modifying the code snippet.
  • The code above is an example of how to automatically update date fields in related records of two modules with a business day offset. You can use this code for any other module, including custom modules, by modifying the module name and other parameters.

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 the Deals module.
  2. Open the deal record for which you want to associate a product.
  3. On the Deal Details page, associate a product in the Select Product lookup field and click Save.
  4. Click on the associated product to view its details.
  5. On the Product Details page, enter a date in the Completion Date field.
    The workflow rule will be triggered.
  6. In the Related List section, select Related Deal, and then click the deal name to view its details.
  7. On the Deal Details page, check whether the Delivery Date field is updated to reflect the completion date plus two business days of the associated product.

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

  • ModuleProducts
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Custom FieldWorkflow 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!