hello forum,
I've written up most of a logic hook that i can't quite seem to finish. I've exhausted research at this point, and i feel i really only need someone to cross my t's and dot my i's
here goes:
here's the object, excuse this as it's going to be a long description.
I'll need 2 hooks, i'm going to talk about 1 for the time being.
The object:
I have created a custom field in accounts "tumclientstatus_c" drop down with 4 values.
There is an existing field in contacts "lead source" i've added the 4 values from the accounts custom field i created to lead source
OR
I've also created a custom field also called "tumclienttype_c" in contacts which is the same as the field by the same name in accounts.
Either would work, although lead source needs less querying than tumclienttype_c as it's in the contacts table rather than the contacts_cstm
i've created some code that would accomplish my goal using tumclienttype_c in contacts_cstm table
let's use this as the scenerio, even though it's most likely more difficult.
I want to create a logic hook that, when an account's tumclienttype_c is changed, it will automatically update ALL the account's assigned contacts tumclienttype_c field to the same.
i've created a file in /custom/modules/accounts/logic_hooks.php
php
$hook_version = 1;
$hook_array = Array();
// working
$hook_array['before_save'][] = Array(1, 'acctTOcont', 'custom/modules/Cases/accounttocontact.php', 'AcctPushCont', 'updateContact');
i've also created a file containing some of the tutorial's aspects, less the bean? The query and php with the commented variables populated correctly should accomplish what i want to do. If it was simply a matter of php, all i'd need is the "current account id" variable (as per the comments)
the file is in the same directory
accounttocontact.php
php
// for sugar
class AcctPushCont {
function updateContact(&$bean, $event, $arguments) {
// currnet account id
$acctid = "";
// current/changed account tumclienttype_c
$acctclienttype = "";
// QUERY grabs all contact id's associated with the account
$res1 = mysql_query("SELECT * FROM `accounts_contacts` WHERE `account_id` = '$acctid' ") or die (mysql_error());
// Creates the batch process for each individual contact associated with the account
while($row = mysql_fetch_array($res1)
{
// Writes the updated value to the contact
mysql_query( "UPDATE `contacts_cstm` SET `tumclienttype_c` = '$acctclienttype' WHERE `id_c` = $row['contact_id']" );
}
}
Granted the bean's are gone as i don't understand their function / purpose.
Seems i'm on the cusp of having a correct syntax, i just have no peers to dot my i's so to speak.
the query ONLY as a query with the php does what i need in theory, so whatever the syntax is it needs rewritten.
The other hook which is actually more important, when creating a new contact, when you select an account to assign it to, it would automatically set the "tumclienttype_c" or "lead source" field to the same status.
Keep in mind i have tumclienttype_c in 2 different places, contacts and accounts... just to make it all more confusing.
any thoughts on this would be helpful.
thanks


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks