Date Time in Android & WCF API

I was working on Android APP related to custom CRM. Where I was to save appointment in database using WCF API. I tried couple of solutions. I tried sending date without time zone offset the WCF API saved 1 hour before timing.  I tried with correct offset of time zone but still facing issue then I tried with and send date time as string without time zone and it worked.

 

 

 
SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

Add hrs and min to date time in Android Java;

 

 

public static Date addMinutesToDate(Date date, int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }

public static Date addHoursToDate(Date date, int hours) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.HOUR_OF_DAY, hours);
    return calendar.getTime();

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;
}
}

Think different!!!