Category Archives: PHP

This section is related to PHP programming, CSS, HTML, Javascript, AJAX, JQuery.

How to set Owner of record in Zoho CRM

I was working on a project by integration records from third party app to Zoho CRM & set the same owner in 3rd party record in Zoho CRM. I used the following code to set the owner. Its code of Zoho CRM PHP Sdk V2.

 


$zcrmUser = ZCRMUser::getInstance($userId, null);
$record->setOwner($zcrmUser);

 

CSV String in API Response

I was working on a project  and was using REST API to import records from third party application to Zoho CRM. The API returns the data in CSV formatted string.  I used PHP and used the following logic to create records in CRM.

 

$csvData = file_get_contents($fileName); // It was actually API call.
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
    $array[] = str_getcsv($line);
}
print_r($array);

Handle API Date In Deluge

I was working on API in Zoho CRM and used deluge script. There I faced problem to handle datetime field to create a record. Zoho use specific format to handle date. It is then solved using the following function.

newdate = zoho.currenttime.addMinutes(30).toString("yyyy-MM-dd'T'HH:mm:ss'+05:30'");

 

In PHP, i faced the similar problem when using PHP Zoho CRM SDK V2.  I then also solved it using the following datatime function.

$dt = new DateTime();

$start_timestamp = $dt->format('c');

 

 

Delete Log files after 10 days

I was creating web hook for an application and needed to write a log , so i created this function as to delete a log file after 10 days as log file size increase with passage of time.

function deleteLogFileAfter10Days()
{
$fileSystemIterator = new FilesystemIterator(‘logs’);
$now = time();
foreach ($fileSystemIterator as $file) {
if ($now – $file->getCTime() >= 60 * 60 * 24 * 10) // 2 days
unlink(‘logs/’.$file->getFilename());
}
}

Send attachment in email deluge script

Send attachment in Email using deluge script Zoho CRM

CRMresponse = zoho.crm.getRelatedRecords(“Attachments”,”Deals”,id.toLong());
opp_info = zoho.crm.getRecordById(“Deals”,id.toLong());
contact_id = ifnull(opp_info.get(“Contact_Name”).get(“id”),””);
contact_info = zoho.crm.getRecordById(“Contacts”,contact_id);
email = ifnull(contact_info.get(“Email”),””);
info email;
if(email != “”)
{
for each record in CRMresponse
{
file_id = record.get(“id”);
downloadFile = invokeurl
[
url :”https://www.zohoapis.com/crm/v2/Deals/” + id + “/Attachments/” + file_id
type :GET
connection:”crmcon”
];
sendmail
[
from :zoho.adminuserid
to :email
subject :”Test subject”
message :”<h2>Test Email</h2>”
content type :HTML
Attachments :file:downloadFile
]
break;
}
}

Create Activities in Vitger using code

How to create Task Activity on Calendar

include_once ‘includes/main/WebUI.php’;
require_once(‘modules/Vtiger/models/Record.php’);
require_once ‘modules/Users/Users.php’;

$recordModel = Vtiger_Record_Model::getCleanInstance(‘Calendar’);
$recordModel->set(‘mode’, ”);
$recordModel->set(‘activitytype’,’Task’);
$recordModel->set(‘subject’,$task_subject);
$recordModel->set(‘date_start’,$startdate);
$recordModel->set(‘time_start’,$time_start);
$recordModel->set(‘due_date’,$startdate);
$recordModel->set(‘time_end’,$time_end);
$recordModel->set(‘taskpriority’,’High’);
$recordModel->set(‘taskstatus’,’Planned’);
$recordModel->set(‘parent_id’,$opp_id);
$recordModel->set(‘set_reminder’,1);
$recordModel->set(‘visibility’,’all’);
$recordModel->set(‘description’,’Test Task’);
$recordModel->set(‘assigned_user_id’,1);
$recordModel->save();
$activityId = $recordModel->getId();