CRM Help

Programming Custom Functions

Deluge or Data Enriched Language for the Universal Grid Environment is an online scripting language integrated with Zoho Creator. It helps you to add different types of business logic to the custom function and make it more powerful. The entire database layer is abstracted and you will only map the arguments with fields, while scripting in Deluge. See Also Deluge Script - Reference Guide

Target Audience

  • CRM Users with Manage Workflow permissions
  • Programmers with Deluge Script knowledge

Availability

Profile Permission Required: Users with the Manage Workflow permissions in can access this feature.

Program Custom Functions

Programming custom function through Deluge Script includes the following three steps:

  • Program a custom function.
  • Associate custom function to a workflow rule.
  • Test the custom function integration.

To program a custom function

  1. Click Setup > Automation > Workflow > Custom Function.
  2. In the Custom Functions page, click the Configure Custom Function.
  3. In the Configure Custom Function page, click the Write your own function link. Writer your Custom Function
  4. In the Deluge Script page, complete the following:
    • Specify name of the function and click the Edit Arguments link.
      Custom Function
    • Edit Arguments box and map the argument with fieild name or custom value in CRM module. Custom Function
    • Click Done.
  5. Write your required function in Deluge Script builder. Click Execute Script to validate your code.
    Write your Deluge Script
    If there are no errors, your script is ready to associate with Workflow Rule.
  6. Click Save & Associate.

To associate custom function to a workflow rule

    1. Click Setup > Automation > Workflow Rules.
    2. In the Workflow Rules page, click the Create a Workflow Rule.
    3. In the Workflow Rule page, specify workflow rule parameters.
    4. Under Workflow Actions, select the custom function to be triggered.
    5. Click Save.

To test the custom function integration

  1. Add test data in CRM according to your workflow rule criteria.
  2. In your application check for the data received from Zoho CRM via custom function.
  3. If there is an error or data mismatch, modify your custom function code in Zoho CRM.
  4. Continue this test until you obtain the required data from Zoho CRM to your Application.

Important Notes

  • You can associate up to 6 (1 Instant Action and 5 Time-Based Actions) custom functions per workflow rule.
  • You can transfer data for a maximum of 10 CRM fields from Zoho CRM to third-party applications using custom function.
  • You can retrieve data from other Apps to Zoho CRM using custom function.
  • You must update the API ticket regularly according to limits in third-party applications.
  • You will not receive any email notification, if the custom function integration stopped functioning due to any issue in a third-party API.
  • If there is any failure in the process, Custom function will send a notification first, Zoho CRM system will send a second notification after 15 min. Thereafter, the system will not send any notifications for that particular workflow trigger.
  • If you exceed the maximum count per day, the system will not send remaining custom function notifications to third-party applications and will notify thw failure to Administrator. 
  • Zoho CRM will the send the data in following standard format for Date and Date Time fields to third-party applications:
    • Date: yyyy-MM-dd
    • Date Time: yyyy-MM-dd hh:mm

Understanding Deluge Script Builder

The Deluge Script Builder helps you to program the custom functions using drag & drop user interface and execute the function within CRM. It enables you to convert the complex application logic into simple deluge code, without remembering the syntax and functions of Deluge Script. It contains the following components:

  • Delug Script Code
  • Deluge Tasks
    • Conditions
    • Miscellaneous
    • Debug
    • List Manipulation
    • Map Manipulation
    • Web Data
    • XML Manipulation
  • Code Execution

Write your Custom Function

 List of Deluge Tasks

Deluge Task Purpose
Conditions
Miscellaneous
Debug
List Manipulation
Map Manipulation
Web Data
XML Manipulation

Example

Business Scenario: Roll up the amount field to parent account when the potential status is "closed won"

Summary

Roll-up amount from each potential (status is closed won) to Total Revenue (custom field) field of the related Account. If customer buys 10 times, you can view the total revenue from Account page, instead of pulling a report linking Potentials and Accounts. Based on the revenue from customer, later you can grade them type A, type B, or type C customers.

Programming Steps

void workflowspace.Rollup_the_Potential_Amount_to_Accounts(int AccountId, string SumUpField) 

  • void is the return type that will return nothing
  • workflowspace is the namespace in the creator just like a folder to group functions
  • Rollup_the_Potential_Amount_to_Accounts is the name of the function
  • AccountId is a parameter, which holds the ID of Account in CRM
  • SumUpField is another parameter, which holds the field label in Account to which the sum amount is updated while triggering the workflow rule.

{    accountID1 = (input.AccountId).toString();

  • Here we are type casting account id to a string    

resp = zoho.crm.searchRecordsByPDC("Potentials", ("accountid"), accountID1);

  • This is a built in method in Deluge Script, which will get the records by searching the field values.
  • Here we specified to search rgw Potential record type which matches the Account Id with the value that is passed as a parameter.    

total = 0.0;

  • Initialising a local variable to calculate the sum of amount.

for each rec in resp

  • Iterating all potentials returned by the above method call.

{       

stage = (rec.get("Stage")).toLowerCase();

  • Fetching the stage field value of each potential.

if (stage.contains("won"))

  • Checking the stage value contains "won" for each potential. If it is true, then it will enter to the next line, otherwise go to the next potential.

{           

total = (total  +  (rec.get("Amount")).toDecimal());

  • Now adding the amount field's value to the local variable       

}    }   

updateResp = zoho.crm.updateRecord(("Accounts"), accountID1, { input.SumUpField : total });

}

  • This method will update the record in CRM. We mentioned the record type as Account matching the field account id with the passed value with the local variable which currently holds the sum up value.

Complete Program

void workflowspace.Rollup_the_Potential_Amount_to_Accounts(int AccountId, string SumUpField)
{
accountID1 = (input.AccountId).toString();
resp = zoho.crm.searchRecordsByPDC("Potentials", ("accountid"), accountID1);
info resp;
total = 0.0;
for each rec in resp
{
stage = (rec.get("Stage")).toLowerCase();
if (stage.contains("won"))
{
total = (total + (rec.get("Amount")).toDecimal());
}
}
updateResp = zoho.crm.updateRecord(("Accounts"), accountID1, { input.SumUpField : total });
}

Business Scenario 2: Roll up the amount field to parent account when the potential status is "closed won"

Summary

Roll-up amount from each potential (status is closed won) to Total Revenue (custom field) field of the related Account. If customer buys 10 times, you can view the total revenue from Account page, instead of pulling a report linking Potentials and Accounts. Based on the revenue from customer, later you can grade them type A, type B, or type C customers.

Programming Steps

void workflowspace.Rollup_the_Potential_Amount_to_Accounts(int AccountId, string SumUpField) 

  • void is the return type that will return nothing
  • workflowspace is the namespace in the creator just like a folder to group functions
  • Rollup_the_Potential_Amount_to_Accounts is the name of the function
  • AccountId is a parameter, which holds the ID of Account in CRM
  • SumUpField is another parameter, which holds the field label in Account to which the sum amount is updated while triggering the workflow rule.

{    accountID1 = (input.AccountId).toString();

  • Here we are type casting account id to a string    

resp = zoho.crm.searchRecordsByPDC("Potentials", ("accountid"), accountID1);

  • This is a built in method in Deluge Script, which will get the records by searching the field values.
  • Here we specified to search rgw Potential record type which matches the Account Id with the value that is passed as a parameter.    

total = 0.0;

  • Initialising a local variable to calculate the sum of amount.

for each rec in resp

  • Iterating all potentials returned by the above method call.

{       

stage = (rec.get("Stage")).toLowerCase();

  • Fetching the stage field value of each potential.

if (stage.contains("won"))

  • Checking the stage value contains "won" for each potential. If it is true, then it will enter to the next line, otherwise go to the next potential.

{           

total = (total  +  (rec.get("Amount")).toDecimal());

  • Now adding the amount field's value to the local variable       

}    }   

updateResp = zoho.crm.updateRecord(("Accounts"), accountID1, { input.SumUpField : total });

}

  • This method will update the record in CRM. We mentioned the record type as Account matching the field account id with the passed value with the local variable which currently holds the sum up value.

Complete Program

void workflowspace.Mass_update_of_Child_Contacts(int accId) { accountId = input.accId.toString(); rec = zoho.crm.getRecordById(("Accounts"), input.accId); resp = zoho.crm.getRelatedRecords("Contacts", ("Accounts"), accountId); for each ele in resp { mp = map(); mp.put("Mailing Street", rec.get("Billing Street")); mp.put("Mailing City", rec.get("Billing City")); mp.put("Mailing State", rec.get("Billing State")); mp.put("Mailing Zip", rec.get("Billing Code")); mp.put("Mailing Country", rec.get("Billing Country")); mp.put("Other Street", rec.get("Shipping Street")); mp.put("Other City", rec.get("Shipping City")); mp.put("Other State", rec.get("Shipping State")); mp.put("Other Zip", rec.get("Shipping Code")); mp.put("Other Country", rec.get("Shipping Country")); contactId = ele.get("CONTACTID"); updateResp = zoho.crm.updateRecord("Contacts", contactId, mp); } 
}

Follow these steps to configure the custom function:

  1. Log in to Zoho CRM.
  2. Open Setup > Automation > Workflow Rules.
  3. Select Potentials from the Module drop-down.
    Custom Function
  4. Under the Excecute On section, select Create or Edit option.
    Custom Function
  5. Under the Rule Criteria section, set the criteria as "Stage" contains "closed won"
    Custom Function
  6. Under the Actions section, click Add Configure Custom Function.
    Custom Function
  7. In the Configure Custom Function page, click the Customized Functions link.
    Custom Function
  8. In the Customized Functions page, click Configure for Roll-up Potential Amount to Accountfunction.
  9. Select the Potential as your module.
  10. Specify values for the arguments as mentioned below:
    • AccountID: Choose "AccountId" column from the list of fields.
    • SumUpField: Specify the field you have in accounts module for the summation.
    • Click "specify custom value" link and type your field name.
  11. Save the configuration to automatically update the sum of the revenue generated by all the potentials of an account in the account module.

Top