The gform_zohocrm_post_create_task action allows custom actions to be performed after creating a task in Gravity Forms.
Usage
add_action('gform_zohocrm_post_create_task', 'your_custom_function', 10, 5);
function your_custom_function($task_record, $task, $feed, $entry, $form) {
// your custom code here
return $task_id;
}
Parameters
$task_record(array) – The task record.$task(array) – The task arguments.$feed(array) – The feed object.$entry(array) – The entry object.$form(array) – The form object.
More information
See Gravity Forms Docs: gform_zohocrm_post_create_task
This action was added in Zoho CRM version 1.8.
Source Code: This action is located in class-gf-zohocrm.php.
Examples
Send an email after task creation
Send an email notification to the admin after a task is created in Zoho CRM.
add_action('gform_zohocrm_post_create_task', 'send_email_after_task_creation', 10, 5);
function send_email_after_task_creation($task_record, $task, $feed, $entry, $form) {
$to = '[email protected]';
$subject = 'New Task Created in Zoho CRM';
$message = 'A new task has been created in Zoho CRM with the following details:' . "\r\n" . print_r($task_record, true);
wp_mail($to, $subject, $message);
}
Add a note to the task
Add a note to the task in Zoho CRM after it is created. For this example, you’ll need the Zoho CRM API v2 PHP SDK.
add_action('gform_zohocrm_post_create_task', 'add_note_to_task', 10, 5);
function add_note_to_task($task_record, $task, $feed, $entry, $form) {
// Load Zoho CRM API v2 PHP SDK and set your API key
require_once 'vendor/autoload.php';
$zcrmConfig = array("client_id" => "YOUR_CLIENT_ID", "client_secret" => "YOUR_CLIENT_SECRET");
ZCRMRestClient::initialize($zcrmConfig);
// Get the access token
$oAuthClient = ZohoOAuth::getClientInstance();
$grantToken = "YOUR_GRANT_TOKEN";
$oAuthTokens = $oAuthClient->generateAccessToken($grantToken);
// Create a note and associate it with the task
$task_id = $task_record['id'];
$note_instance = ZCRMNote::getInstance(null);
$note_instance->setTitle("Sample Note");
$note_instance->setContent("This is a sample note added after creating the task.");
$note_instance->setParentId($task_id);
$note_instance->setParentModule('Tasks');
$response = $note_instance->create();
}
Update a custom field in the task
Update a custom field in the task in Zoho CRM after it is created. For this example, you’ll need the Zoho CRM API v2 PHP SDK.
add_action('gform_zohocrm_post_create_task', 'update_custom_field_in_task', 10, 5);
function update_custom_field_in_task($task_record, $task, $feed, $entry, $form) {
// Load Zoho CRM API v2 PHP SDK and set your API key
require_once 'vendor/autoload.php';
$zcrmConfig = array("client_id" => "YOUR_CLIENT_ID", "client_secret" => "YOUR_CLIENT_SECRET");
ZCRMRestClient::initialize($zcrmConfig);
// Get the access token
$oAuthClient = ZohoOAuth::getClientInstance();
$grantToken = "YOUR_GRANT_TOKEN";
$oAuthTokens = $oAuthClient->generateAccessToken($grantToken);
// Update the custom field in the task
$task_id = $task_record['id'];
$task_instance = ZCRMTask::getInstance($task_id);
$task_instance->setFieldValue("Custom_Field_API_Name", "Updated Value");
$response = $task_instance->update();
}
Log task creation
Log task creation details to a file after a task is created in Zoho CRM.
add_action('gform_zohocrm_post_create_task', 'log_task_creation', 10, 5);
function log_task_creation($task_record, $task, $feed, $entry, $form) {
$log_file = 'task_creation.log';
$log_message = 'Task created in Zoho CRM: ' . print_r($task_record, true) . "\r\n";
file_put_contents($log_file, $log_message, FILE_APPEND);
}
Send a Slack notification
Send a Slack notification after a task is created in Zoho CRM. Make sure you replace your_slack_webhook_url with your actual Slack webhook URL.
add_action('gform_zohocrm_post_create_task', 'send_slack_notification', 10, 5);
function send_slack_notification($task_record, $task, $feed, $entry, $form) {
$webhook_url = 'your_slack_webhook_url';
$message = 'A new task has been created in Zoho CRM with the following details:' . "\n" . print_r($task_record, true);
$payload = json_encode(array(
'text' => $message
));
$args = array(
'body' => $payload,
'headers' => array(
'Content-Type' => 'application/json'
)
);
wp_remote_post($webhook_url, $args);
}
In this example, the send_slack_notification function sends a message to Slack using the webhook URL provided. It converts the task details into a message and sends it as a JSON payload using the wp_remote_post function. Make sure to replace your_slack_webhook_url with your actual webhook URL obtained from Slack.