Hi all.
I've created a logic hook which basically checks if the record is updating and if so, check if there is a contact assigned and if not, do not allow save. This works fine on my test site but not on a customers site. They have two issues:
1) The first being when they save an account, it's also running this code, can I ONLY have this code run if the record is saved directly in opportunities?
2) Is there anyway to stop the code firing on import? So only on an actual edit it triggers?
Here is my code:
class oppcontactcheck
{
function validateDuplicateRecord( $bean, $event, $arguments )
{
if (!isset($arguments['isUpdate']) || $arguments['isUpdate'] == true)
{
//Opens Database variable
global $db;
$crm_id = $bean->id;
//Checks how many leads exist with the criteria contact name and mobile number
$oppContactCheck = "select count(*) as count from opportunities o join opportunities_contacts oc on o.id = oc.opportunity_id join contacts c on c.id = oc.contact_id"
. " where o.id = '".$crm_id."'";
$oppContactCheckResult = $db->query($oppContactCheck, true, 'Error Update');
$row = $db->fetchByAssoc($oppContactCheckResult);
//Assigns the count of the above to a variable
$count = $row['count'];
$id;
$conn = $GLOBALS['db']->getConnection();
$GLOBALS['log']->info('### Count: ' . $count);
//Change this to change the message that pops up
$duplicateoppContactMessage = "Please add a contact to the record";
//Checks if count is greater than 0
if ($count == 0)
{
throw new SugarApiExceptionInvalidParameter($duplicateoppContactMessage);
}
}
}
}
/resized-image/__size/320x240/__key/communityserver-discussions-components-files/54/Capture.PNG
I've also added a picture as my formatting is being wiped when copying.
Thanks!