I have logic hook which changes custom field on Accounts after add/delete relationship to Contacts (simply I count related Contacts).
Everything works fine but after logic I need to refresh DetailView to show proper value of updated custom field.
Any help ?
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not a valid entry point');
class contacts_after_relationship_add
{
function after_relationship_add_delete ($bean, $event, $arguments)
{
if ($arguments['module'] == "Accounts" && $arguments['related_module'] == "Contacts"){
$account = new Account();
$account->retrieve($_REQUEST['record']);
$contacts = $account->get_linked_beans('contacts','Contact');
$a = 0;
foreach ( $contacts as $contact ) {
$a++;
}
$bean->amg_kontakty_coun_c = "$a";
$bean->save();
}
}
}
At the account details view, I have a custom field “Number of contacts”
My hook is after_relationship_add and after_relationship_delete
After add/remove contact relations on the Contacts subpanel, I save the current number of contacts
My goal is to refresh the “Number of contacts” value on detail view.
Of course, when I go to another view and return to the account view, I see the correct value, but my goal is to show the actual value immediately after adding / removing the relationship.
I’ve been working through adding a after_relationship_add logic hook and I saw this behavior when I had a php error in my logic hook code that was causing the php to halt mid-step. Once I cleared up the php coding issues the page would refresh on adding a related record. Try adding some debug statements like
$GLOBALS['log']->fatal('***Some debug text***');
to your logic hook’s class function so you can see how far your code is progressing by watching your suitecrm.log after you trigger the code.
Video on that page shows the script, just replace what’s between script tags with “window.location.reload();” and it will reload the whole page instead of a subpanel. I’m still looking how to update just a field and will come back with an answer if I find it.