Hi,
I have made a logic hook that lets users update fields for existing contacts directly within an invoice from a relate field, this works very well.
I have also made it so that it adds new contacts to the database if they do not exist! The only problem is once the page is refreshed the relate field is blank and the user has to manually type in the name of the contact that they just created (it does come up though).
What I want to do is finish off the logic hook by making it take the newly created contact record (name and ID) and insert it into those fields.
I have tried something below but it gives me an error.
Any ideas?
Thanks
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class ContactManagement {
function CreateContact(& $focus, $bean, $event, $arguments){
global $current_user, $db;
$query = "SELECT id FROM contacts WHERE id='".$focus->billing_contact_id."' AND last_name like '".$focus->billing_contact_name_c."';";
$result = $db->query($query, true,"Error reading tasks entry: ");
$row = $db->fetchByAssoc($result);
if($row != null) {
$taskid = $row['id'];
$query = "UPDATE contacts SET modified_user_id='".$current_user->id."', department='".$focus->clientcompany_c."', assigned_user_id='".$current_user->id."', date_modified=now(), deleted='0', id='".$focus->billing_contact_id."', description='".$focus->clientaddress_c."', phone_work='".$focus->contactofficephone_c."' WHERE id='".$taskid."';";
$result = $db->query($query, true,"Error updating tasks entry: ");
} else {
$query = "INSERT INTO contacts (id, last_name, phone_work, department, description) VALUES (uuid(), '".$focus->billing_contact_name_c."', '".$focus->contactofficephone_c."', '".$focus->clientcompany_c."', '".$focus->clientaddress_c."');";
$result = $db->query($query, true,"Error setting tasks entry: ");
$billing_contact = '".$focus->billing_contact."';
$billing_contact_id = uuid();
$bean->save();[
}
}}