Install Actions

Install Actions

Sometimes, you might want your extension to run a customized script immediately after installation or upgradation. For example, you might want to create sample data, or send an email notification about the installation to the CRM users or to an external system, or kick off a batch operation to populate a new field across a large set of data. This cannot be achieved with the help of a custom function or workflow rules. To help you achieve this, Zoho Developer allows you to bundle a post install script along with your extension.

The post install scripts are small snippets of codes or commands that are to be executed immediately after the extension is installed or updated.

 Create a post install script

To add a post install script to your extension

  1. Log in to your Zoho Developer console and click Extensions for Zoho CRM.
  2. Select the extension you'd like to modify and click Edit.
  3. Select Post Install Script in the left pane.
  4. In the Deluge Script Editor, write the required code.
  5. Click Save and Execute if you want to test your code or else simply click Save.

Note

  • You can write only one post install script per extension.
  • The post install script gets triggered automatically when the extension is installed or updated.
  • This script can be triggered only once.

 InstallParamMap Variable

The installParamMap variable can be used only with the post install script and is used to obtain the following data from Zoho CRM:

  • Organization ID - The unique Organization ID of the Zoho CRM account in which the extension is installed. The syntax to obtain the org ID is 
    <variable_name>= input.installParamMap.get("organizationId");
  • Installer ID - The email address of the user who installs the extension. The syntax to obtain the installer ID is
    <variable_name>= input.installParamMap.get("installerId");
  • IsInstall - This is used to check whethere the extension is installed for the first time or is an upgradation. The syntax for this task is
    <variable_name>= input.installParamMap.get("isInstall");
  • PreviousVersion - The value of the previous version of the extension in case of an update. The syntax to obtain the previous version number is
    <variable_name>= input.installParamMap.get("previousVersion");

 Example

Consider the following scenario, A user who installs your extension wishes to alert all the other users in the CRM system about the installation via an email. This can be achieved with the help of a simple post install script.

orgid = input.installParamMap.get("organizationId");
installerid = input.installParamMap.get("installerId");
isInstall = input.installParamMap.get("isInstall");
pversion = input.installParamMap.get("previousVersion");

sendmail
(
To       :  zoho.adminuserid
From     :  zoho.adminuserid
Subject  :  "Post Install script executed"
Message  :  "Installation details ---> OrgId = " + orgid + " : Installer Id = " + installerid + " : is Install = " + isInstall + " : previous version = " + pversion
)

This script when executed, sends an email to admin of the CRM system with the details of the extension and the user who installed the extension.
Similarly you can perform any action using the post installer script.

 Delete a post install script

To delete a post install script

  1. Log in to your Zoho Developer console and click Extensions for Zoho CRM.
  2. Select the extension you'd like to modify and click Edit.
  3. Select Post Install Script in the left pane.
  4. Remove the existing code and click Save.
  5. Publish the extension again to make this change effective.

 Create an on authorization script for connectors

Occasionally, you might want to run a customized script immediately after a connector has been authorized. For example, you might want to register webhooks or create users. These objectives cannot be achieved with a custom function or workflow rules. To help you achieve this, Zoho Developer allows you to create an add-on script that will get executed post authorization of the connector.

The post authorization script is a snippet of code or command that is to be executed after authorization of the connector.

To include a post authorization script for a connector:

  1. Click Extensions for Zoho CRM in the Zoho Developer console homepage.
  2. Select the extension that the connector has been associated to.
  3. Click Install Actions in the left pane.
  4. Click Connector - On Authorization.
  5. Select the connector that you want to include the authorization script in.
  6. Write the required code in the Deluge Script Editor.
  7. Click Execute if you want to test your code, or simply click Save to Connector.

Note

  • You can only write one post authorization script per connector.
  • The post authorization script gets triggered automatically when the connector is authorized.
  • This script will be triggered every time the connector is authorized.

 Example

Consider a scenario where a user wants to register a webhook that will notify the CRM system when appointments are scheduled (created) in an external system. When this event of receiving a notification is not associated with any user action or input in the CRM system, it can be triggered by including a post authorization script for the connector. Thus, the webhook will be created when the extension that has the connector is used in the CRM system.  Similarly, you can perform any action using the post authorization script for connector.

getmap = { "nameSpace" : "<portal_name.extension_namespace>"};
apiresponse = zoho.crm.invokeConnector("crm.zapikey", getmap);
zapikey = apiresponse.get("response");
crm_signal_webhook_url = "https://platform.zoho.com/crm/v2/settings/custom_function/acuityschedulingext.createevent/execute?zapikey=" + zapikey;
scheduledMap = { "triggerEvent" : "appointment.scheduled", ("targetUrl") : crm_signal_webhook_url };
response = zoho.crm.invokeConnector("acuityschedulingext.acuityscheduler.regsiterwebhook", scheduledMap);
info response;
webhookid = response.get("id");
setResp = zoho.crm.invokeConnector("crm.set", { "apiname" : "acuityschedulingext.webhookid", "value" : webhookid });

For registering a Webhook, a deluge function needs to be defined that can be exposed as a REST API. Once this function (createevent) is defined and saved, the REST API URL will be generated. This URL  (https://platform.zoho.com/crm/v2/settings/custom_functions/acuityscheduling .createevent) is the Webhook URL that has to be provided to the third-party application. The code for the function is given below:

resp = input.requestMap;
appointmentId = resp.get("id");
getsingleappointmentMap = { "id" : appointmentId };
response = zoho.crm.invokeConnector(("acuityschedulingext.acuityscheduler.getsingleappointment"), getsingleappointmentMap);
responseMap = (response.get("response")).toMap();
fName = responseMap.get("firstName");
lName = responseMap.get("lastName");
mobile = responseMap.get("phone");
email = responseMap.get("email");
eventName = responseMap.get("type");
createContactMap = { "First_Name" : fName, "Last_Name" : lName, "Mobile" : mobile, "Email" : email };
m = map();
l = List();
l.add(createContactMap);
m.put("module", "Contacts");
m.put("data", l);
contactResp = zoho.crm.invokeConnector("crm.create", m);
info contactResp;
newContactResp = (contactResp.get("response")).toMap();
newDataMap = (newContactResp.get("data")).toMap();
contactId = newDataMap.get("id");
createEventMap = { "Event_Title" : eventName, "Who_Id" : contactId, "All_day" : false, "Start_DateTime" : ("2017-09-08T15:58:00+05:30"), "End_DateTime" : ("2017-09-08T15:58:00+06:30") };
mapp = map();
lapp = List();
lapp.add(createEventMap);
mapp.put("module", "Events");
mapp.put("data", lapp);
EventResp = zoho.crm.invokeConnector("crm.create", mapp);
info EventResp;

Note

For more details about registering webhooks, refer to the guide on Custom SalesSignal 

In the example mentioned above, after the webhook is successfully created, new record will be added in Contacts and Events module whenever a new appointment is created in the third-party application. The ID of the newly created webhook is set as an organization variable so that the value of the ID is available globally to be used at a later stage. To set the organization variable, follow the below steps:

  1. Click on Extension Settings in the left pane.
  2. Click Create.
  3. Enter the values as shown below:
  4. Click Save.

After the webhook is successfully created, the following response will be obtained:

 Create an on revoke script for connectors

After revoking the authorization of a connector, it might become necessary to nullify the workflow/action(s) associated with the connector. For example, you might want to disallow users from sending mail/SMS. These objectives cannot be achieved with the help of a custom function or workflow rules. To help you achieve this, Zoho Developer allows you to add a script (snippet of code or command) which will get executed during revocation of authorization of the connector.

To include a script post revocation of authorization of a connector:

  1. Click Extensions for Zoho CRM in the Zoho Developer console homepage.
  2. Select the extension that the connector has been associated to.
  3. Click Install Actions in the left pane.
  4. Click Connector - On Revoking.
  5. Select the connector you want to add the script to be executed in after revocation of the connector authorization.
  6. Write the required code in the Deluge Script Editor.
  7. Click Execute if you want to test your code, or simply click Save to Connector.

Note

  • You can only write one post connector revocation script per connector.
  • The post connector revocation script gets triggered automatically when the authorization of the connector is revoked.
  • This script will be triggered every time the connector authorization is revoked.

 Example

On revocation of the connector authorization, a registered webhook is deleted.

webhookid = zoho.crm.getOrgVariable("acuityschedulingext.webhookid");
m = { "id" : webhookid };
resp = zoho.crm.invokeConnector("acuityschedulingext.acuityscheduler.deletewebhook", m);
m = { "apiname" : "acuityscheduling.webhookid", "value" : 0 };
setOrgVar = zoho.crm.invokeConnector("crm.set", m);

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohodeveloper.com