YetiForceCompany / YetiForceCRM

Our team created for you one of the most innovative CRM systems that supports mainly business processes and allows for customization according to your needs. Be ahead of your competition and implement YetiForce!
https://yetiforce.com
Other
1.74k stars 749 forks source link

[Question] Invoke custom function. Yetiforce vs Vtiger. Different approach? #11659

Closed LaurensCleyman closed 5 years ago

LaurensCleyman commented 5 years ago

Hi all,

I want to invoke a custom function in my workflows. When I used Vtiger then the code below worked. In YetiForce this is different. Any ideas what is changed?

Goal: Calculate the age of a contact based on his birthday, then store this value in the field 'age'.


<?php

chdir(dirname(__FILE__) . '/..');
require_once 'include/utils/utils.php';

global  $adb;

function calculateAge($entity){

    global  $adb;

    $entity_id = vtws_getIdComponents($entity->getId());
    $id = $entity_id[1];

    $birthday   = $entity->get('birthday');
    $age = 0;

    $from = new DateTime($birthday);
    $to   = new DateTime('today');
    $age  =  $from->diff($to)->y;

    $result = $adb->pquery("update vtiger_contactdetails
    set age = ? where contactid = ?  ",array($age,$id));
}

?>
mariuszkrzaczkowski commented 5 years ago

you have to rewrite everything, see example

https://github.com/YetiForceCompany/YetiForceCRM/blob/5c54c0efbe408ec6c0027a16d99f7a1d68f61968/modules/Users/workflows/UsersWorkflow.php#L12-L29

https://github.com/YetiForceCompany/YetiForceCRM/blob/5c54c0efbe408ec6c0027a16d99f7a1d68f61968/modules/HelpDesk/workflows/HelpDeskWorkflow.php#L9-L157

LaurensCleyman commented 5 years ago

Ok I'm a step closer thanks to the examples.

But how can I update the field 'age' with the result?

<?php

class ContactsWorkflow
{
    public static function Leeftijd(Vtiger_Record_Model $recordModel)
    {
        \App\Log::trace('Entering leeftijd');

        $birthday = $recordModel->get('birthday');
        $id = $recordModel->get('contactid');

        $from = new DateTime($birthday);
        $to   = new DateTime('today');
        $age  =  $from->diff($to)->y;*/

        //How to:
        //UPDATE vtiger_contactdetails
        //SET age = $age
        //WHERE contactid = $id

        \App\Log::trace('leeftijd');
    }
}
z0lo13 commented 5 years ago

@LaurensCleyman $recordModel->set('age', $age) $recordModel->save();