Results 1 to 6 of 6

Thread: Link records with logic hooks

  1. #1
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Link records with logic hooks

    Hi,

    is there a way to create a relationship between two modules with a logic hook?
    I have my custom module and every time i have an one field changed to 'Client' the logic hook will create a record and link it to the account. The modules have a many-to-many relationship.
    Is there a way to do this not using SQL?
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  2. #2
    jeremy.roberts is offline Junior Member
    Join Date
    Oct 2009
    Posts
    4

    Default Re: Link records with logic hooks

    Yes! You should first create the account, then from either the account or your custom module, do

    $focus->load_relationship(REL_NAME);
    $focus->REL_NAME->add(ID_OF_OTHER_BEAN);

    Example:

    $focus is an Opportunity

    $focus->load_relationship('accounts');
    $focus->accounts->add($account->id);

    You don't even need to save either been after this. The add() function writes to the relationship table in the database.


    That's it! They're now linked!

  3. #3
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Link records with logic hooks

    tyty! thats execly what i was loking for
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  4. #4
    Phil77 is offline Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Red face Re: Link records with logic hooks

    Hi everybody,

    I am struggling a little with a similar problem:
    I want to connect a Lead - created through the WebToLead form - to be automatically added as an attendee of a known meeting ("known" as in: we will compare a date given form a custom field and assign it to an existing event, hence we know the ID of the event - but that's beside the point); what I have figured out is, that I have to create a relationship between the lead and the event.
    I tried to implement the above, but I seem to be missing something.

    Thanks for your help!
    Philip

  5. #5
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Link records with logic hooks

    Hi Philip

    Just to make sure your needs: You want to invite the new Lead to an existing meeting, right?
    So you just need to add a relationship between them:
    As you told before you are able to identify the meeting whose date start matches some date field from form, so:


    PHP Code:
    $lead->load_relationship('meetings');
    $lead->meetings->add($meeting_id); 
    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  6. #6
    Phil77 is offline Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Default Re: Link records with logic hooks

    Thanks André, it worked!
    ...stupid mistake on my part, but your post helped to identify it!

    Thanks, Philip

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Logic Hooks
    By Rajesh Patel in forum Help
    Replies: 6
    Last Post: 2009-11-18, 05:57 PM
  2. Logic Hooks
    By chrislynch8 in forum Help
    Replies: 3
    Last Post: 2009-07-16, 11:08 AM
  3. Logic Hooks
    By highres in forum Italiano
    Replies: 3
    Last Post: 2009-02-01, 05:10 PM
  4. Problem to insert records in logic hooks
    By sugar78 in forum Developer Help
    Replies: 2
    Last Post: 2008-11-12, 01:07 PM
  5. Logic Hooks
    By Delos in forum Developer Help
    Replies: 0
    Last Post: 2008-10-17, 01:01 AM

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
  •