Results 1 to 2 of 2

Thread: logic hook before save syntax

  1. #1
    tellusmore is offline Senior Member
    Join Date
    Jun 2009
    Location
    Pittsburgh
    Posts
    60

    Default logic hook before save syntax

    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

  2. #2
    tellusmore is offline Senior Member
    Join Date
    Jun 2009
    Location
    Pittsburgh
    Posts
    60

    Cool Re: logic hook before save syntax

    I got it forum, if you need help message me, i'd post the solution however it's specific to what i wanted to do.

    here's a tutorial that worked for me:
    http://cheleguanaco.blogspot.com/200...k-example.html

    give that a look first...

    also get familiar with the custom/ directory, if you have multiple instances of sugarce it makes duplicating them as simple as uploading the folder. ALL your customizations end up here. module loader export import works to some extent, the folder itself i found to be much more reliable without touching the core.

    don't forget the semi colons!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cancel save in logic hook
    By eggsurplus in forum Developer Help
    Replies: 4
    Last Post: 2012-02-08, 09:37 AM
  2. Redirect in save Logic Hook
    By Mithun in forum Developer Help
    Replies: 10
    Last Post: 2009-12-03, 02:43 AM
  3. Logic Hook - before save problem
    By kinshibuya in forum Help
    Replies: 7
    Last Post: 2009-07-21, 07:00 PM
  4. save & skip logic hook
    By mikesolomon in forum Developer Help
    Replies: 2
    Last Post: 2008-11-05, 12:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •