Format and update the date time organization variable

Format a date time org variable to show two weeks later for use in email templates, webinar invitations, or custom functions.

Do you want to invite your leads to a webinar that will take place in two weeks from the time you added them? Are you interested in streamlining your CRM's various date and time formats? This custom function can help you format a date/time variable to show two weeks later. You can utilize this formatted date/time variable as merge fields in email templates, webinar invitations, or other custom functions. The formatting also makes working with dates in CRM easier and avoids problems with incorrect formats.

To achieve this, create a date/time organization variable in your CRM and write a function that sets its value to two weeks later in the required format based on its current date/time value.

 

Solution by : Andrew, Aether Automation

Permissions and availability

  • Users with the Manage Zoho CRM Variables permission can create variables.
  • Users with the Manage Extensibility permission can write custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a new date/time organization variable by specifying a current or a custom date and time.
  • Write a standalone custom Deluge function using the code snippet provided below. Learn more
  • Test the function in a sandbox environment before deploying it to your production environment. Learn more
     

Create a variable

To begin, create a new date/time organization variable and ensure it is set to the necessary date and time.

  1. Navigate to Setup > Developer Space > Zoho CRM Variables > +Create New Variable.
  2. Provide a name and API name for the variable. For example: "orgDateTime". 
  3. Set the type of the variable as Date/Time.
  4. Enter the date and time. For example: "Feb 15,2024 11:00 AM"
  5. Choose where your variable should be grouped.
    You can also create a new group, if necessary.
  6. Click Save.
     
Create Variable

Write a custom function

The final step is to write the standalone custom function that retrieves the date and time from the org variable, updates them by adding the specified number of weeks, formats its structure, and finally updates the org variable in CRM.

  1. Navigate to Setup > Developer Space > Functions > +New Function.
  2. Provide a name and display name for the function. For example: "Update Org Date Two Weeks Later".
  3. Select the category of the function as Standalone.
  4. Copy and paste the code provided below.
  5. Click Save.

The code

Code Copied
//Specify how many weeks forward the date should be updated
weeksIntoTheFuture = 2;

//Fetch the org date time from variable
orgDateTime = zoho.crm.getOrgVariable("orgDateTime");

//Update date into the future
orgDateTimeList = orgDateTime.toList(" ");
orgDate = orgDateTimeList.get(0);
formatedDate = orgDate.toString("yyyy-MM-dd");
updatedFormatedDate = formatedDate.addWeek(weeksIntoTheFuture).toString("yyyy-MM-dd");

//Format the processed date/time
formatedDateTime = updatedFormatedDate.toString("MM/dd/yyyy") + " " + orgDateTimeList.get(1) + " " + orgDateTimeList.get(2);

//Update the org date/time variable
valueMap = map();
valueMap.put("apiname","orgDateTime");
valueMap.put("value",formatedDateTime);
info zoho.crm.invokeConnector("crm.set", valueMap);
return "";

Note

  • The script above is an example of formatting a date/time org variable to show two weeks later. You can customize this code for other custom time periods by changing the parameters.

Test the solution

  1. Navigate to Setup > Developer Space > Zoho CRM Variables.
  2. Check the orgDateTime variable and confirm that it displays a date/time value, which should be "Feb 15,2024 11:00 AM", as per our example.
  3. Return to the Functions page and click on the Save & Execute button.
  4. See whether the orgDateTime variable's date/time value is updated two weeks later per the function, which is supposed to be "Feb 29,2024 11:00 AM".

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

  • ModuleVariables
  • Trigger PointManual
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

VariableDeluge 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!