Results 1 to 3 of 3

Thread: Logic Hook to Relate Modules

  1. #1
    PHiSH is offline Junior Member
    Join Date
    Jun 2011
    Location
    Arizona
    Posts
    8

    Default Logic Hook to Relate Modules

    I have two modules, leads and payments, that I want to relate via a logic hook. I have several fields saving correctly from the leads editview into the payments module but the two aren't relating on the save. I've seen several examples but I can't quite figure it out. The relationship is one lead to many payments. The version is 6.3.1 CE. Could anyone please give me a simple example on how to get the two to insert the relationship into the database properly? I'd prefer to use beans over inserting directly into the database if that's possible. Thanks!

    Here is the code I've been using so far...
    Code:
    function insertPayments(&$bean, $event, $arguments) {
    
    		$custDownPay = 0; 
    		$weekBtwn = 0;
    		$payAmnt = 0;
    	
    		$leadID = $bean->id;
    		
    		$objPayment = new pay_Payments();
    			$objPayment->load_relationship('Leads');
    			$leadID = $bean->id;
    			$objPayment->id = $leadID;
    			$payAmt = $bean->payments_amount_c;
    			$objPayment->payment_amount = $payAmnt;
    			$weekBtwn = $bean->weeks_btwn_pay_c;
    			$objPayment->weed_btwn_pay = $weekBtwn;
    			$objPayment->save();			
    	}

  2. #2
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Logic Hook to Relate Modules

    Try the following functions:
    $bean->load_relationship('rel_name');
    $bean->rel_name->add($other_bean_id);
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  3. #3
    PHiSH is offline Junior Member
    Join Date
    Jun 2011
    Location
    Arizona
    Posts
    8

    Default Re: Logic Hook to Relate Modules

    Quote Originally Posted by rafael.q.g@hotmail.com View Post
    Try the following functions:
    $bean->load_relationship('rel_name');
    $bean->rel_name->add($other_bean_id);
    Thank you very much! I had the wrong relationship name the entire time. I found the relationship in the relationships table (my dumb mistake).

    For anyone else who comes across this, I got it working with this code:
    Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once('/modules/pay_Payments/pay_Payments.php');
    global $db;
    class CreatePayments {
    	function insertMultiPayments(&$bean, $event, $arguments) {
    		$custDownPay = 0;
    		$weekBtwn = 0;
    		$payAmnt = 0;
    		$leadID = $bean->id;
    		
    		$objPayment = new pay_Payments();
    			$objPayment->load_relationship('pay_payments_leads');
    			$payAmt = $bean->payments_amount_c;
    			$objPayment->payment_amount = $payAmnt;
    			$weekBtwn = $bean->weeks_btwn_pay_c;
    			$objPayment->weed_btwn_pay = $weekBtwn;
    			$objPayment->save();
    
    			$objPayment->load_relationship('pay_payments_leads');
    			$objPayment->pay_payments_leads->add($bean->id);
    	}	
    }
    Thanks again,

    Ryan

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Logic Hook for All Modules
    By chadhutchins in forum Developer Help
    Replies: 3
    Last Post: 2012-01-20, 08:35 AM
  2. Logic Hook after relate field selected
    By leowolff in forum Help
    Replies: 2
    Last Post: 2012-01-16, 10:50 AM
  3. Replies: 5
    Last Post: 2011-04-03, 07:00 PM
  4. Logic hook, relate new bug
    By cmacholz in forum Developer Help
    Replies: 2
    Last Post: 2009-12-15, 02:17 PM
  5. Replies: 3
    Last Post: 2009-08-15, 03:00 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
  •