Update CRM Variables with Additional Business Logic

Update CRM Variables with Additional Business Logic

Update CRM Variables with Additional Business Logic

ZOHO CRM Variables provide the ability to store static values that can be updated in one spot and used across multiple functions within a ZOHO deployment.

Specific Events, Actions or responses to another function call can create a requirement to iterate or update these static CRM Variables and it would be much nicer to handle this programatically with a Standalone Function.

EDIT : Specific Events, Actions or Responses to another function call can create a requirement to update or iterate these static CRM VariablesRather than simply using the invokeConnector Deluge task which is a wrapper function for the invokeurl API call, it would be nice to run our own business logic with the update and handle this within a wrapper function like invokeConnector that we can define and call with minimal inputs across our deployment, this is achieved with a Standalone Function.

NOTE: Additional features are not covered under this Discussion.

Prerequisites

Connection

Using the invokeurl webhook method requires a Connection within your ZOHO deployment to make an API call to the CRM Variables endpoint. If you do not already have one setup, follow the ZOHO Developer docs here -> zoho.com/crm/developer/docs/connectors/set-up.html

Or alternatively, you can use the invokeConnection task, both methods are shown below.

CRM Variable

This example uses the id of an existing CRM Variable within your ZOHO CRM deployment. If you do not already have a CRM Variable setup, we'll do that now. If you do, copy the id and save that for a later step.

To create a CRM Variable go to Setup -> Developer Space -> ZOHO CRM Variables -> Create New Variable

  • Variable Name = test_variable
  • API Name = test_variable
  • Description = This is a test variable.
  • Variable Type = Single Line (For future reference this should macth the data type of the variable required)
  • Value = "MY TEST VARIABLE"
  • Grouped Under -> Create New Group
    • Group Name = test group
    • Group API Name = test_group
    • Description = This is a test group.
    • Click Save
  • Click Save
  • Click the Pencil Edit Icon to the left of the Variable Name
  • Copy the Variable ID from your web browser address bar, we'll need this later.

Create the Standalone function

We will now create the Standalone Function which can be called from any other function or WorkFlow.

Setting Up Standalone Function

To setup the standalone function:

  1. Go to Setup -> Functions -> New Function
  2. Name the function "update_crm_variable" and under Category select  Standalone. Click  Next.
  3. You'll be taken to the Deluge code editor.
  4. Edit your standalone function as below to use an API call :

    1. /* RUN SOME BUSINESS LOGIC HERE */
    2. // PASS VALUES FROM BUSINESS LOGIC INTO MAP
    3. /* update_crm_variable */
    4. variable_map = Map();
    5. variable_map.put("id",variable_id);
    6. variable_map.put("value",variable_value);
    7. variable_list = List();
    8. variable_list.add(variable_map);
    9. param = Map();
    10. param.put("variables",variable_list);
    11. update_variable = invokeurl
    12. [
    13.     url : "https://www.zohoapis.com/crm/v2/settings/variables"
    14.     type :PUT
    15.     parameters:param.toString()
    16.     connection: "YOUR_CONNECTION_NAME"
    17. ];
    18. /* RUN SOME OTHER BUSINESS LOGIC HERE */
    19. // TAKE RESPONSE FROM INVOKEURL
    20. //info update_variable;
    21. return update_variable;

    Or edit your standalone function as below to use the invokeConnector :

    1. /* update_crm_variable */
    2. variable_map = Map();
    3. variable_map.put("apiname","test_variable");
    4. variable_map.put("value",variable_value);
    5. variable_map.put("crm.set",variable_map);

  5. Click Edit Arguments and add the following two Function Arguments

    1. variable_id as type String
    2. variable_value as type String
    3. Click  Save

  6. Click  Save.

We can now move on to the requesting function.

Setting Up A Requesting Function

To setup a requesting function:

  1. Go to  Setup -> Functions -> New Function
  2. Name the function and select any Category. Click  Next.
  3. You'll be taken to the Deluge code editor.
  4. Edit your standalone function as below :

    1. /* REQUESTING FUNCTION */
    2. id = "YOUR_VARIABLE_ID_FROM_THE_PREVIOUS_STEP";
    3. value = "MY UPDATED VARIABLE";
    4. response = standalone.update_crm_variable(variable_id,variable_value);
    5. info "Response : " + response;

  5. Click  Save & Execute.

When you execute this requesting function, you should see the response printed in the console:

  1. /* CONSOLE */
  2. Info
  3. {"variables":[{"code":"SUCCESS","details":{"id":"YOUR_VARIABLE_ID_FROM_THE_PREVIOUS_STEP"},"message":"variable updated","status":"success"}]}
  4. Function executed successfully.

Check Your Updated Variable

To check this has worked:

  • Go to Setup -> Developer Space -> ZOHO CRM Variables

  • Check your variable value has changed to "MY UPDATED VARIABLE"

Using this method you can now automate updates on ZOHO CRM Variables.

EDIT : Why not just use invokeConnector?

The entire ZOHO ecosystem is API driven and clearly the invokeConnector deluge task does the same/similar thing under the hood as the invokeurl webhook. invokeConnector can also be used within the Standalone function to do the update, which method you use is really irrelevant to the outcome as they are functionally the same.

However, if you are applying the method in this Discussion to other use cases the invokeConnector is limited to existing predefined Associated Connectors or building your own ZOHO CRM Vertical Solution which adds its own inherent complexity.

If you want to do more than just update one record or you have specific dependent business logic you need to reuse across your ZOHO deployment, but want a reusable function, a Standalone function can provide the same simple features of the invokeConnector, with the added flexibility of computing additional business logic with flexible and definable inputs from the requesting function.






                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now