How do you autopopulate a related field in custom module from a related field of another module?

I'm fighting against this issue since a couple of weeks and I can't figure out a way to do that.

I have a custom module for the orders management and I need to produce invoices automatically.
I'm following the example of 'ConverToInvoice.php' from Quotes module so, if I click on that button (under the Edit button in Detail View) I should create a new Invoice whose fields are pre-filled and  editable.
I have to grab fields' values from current order management.
My first problem is that a lot of those fields are related, too.

For example, I need to fill a related field called 'Suppliers' in my invoice. The value I need comes from a module (Suppliers) related to the Account, which is related to the current order management.

How can I easily grab that value and put it in my suppliers field?

I tryed to follow this guide  but it didn't worked.. probably I miss something.
I really need help, as soon as possible.

Thank you.

Parents
  • Hi there

    I have  a similar problem like you are managing in this post. I have created two custom modules with a one to one relationship

    R2_Microchip has a one to one relathichip with R2_Solicitud. I am builing a button in the DetailView of the R2_Solicitud module and this button calls a controller function that needs to take the related R2_Microchip and work with it.

    To do so i need to know the relationship between these two modules to be able to call it.

    I have found in this forum a post that points to  this blog

    http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-...

    However in my code, when I call this function this way

    $rel_microchip = getRelationshipByModulesgetRelacion("R2_Solicitud","R2_Microchip");

    $bean_solicitud->load_relationship($rel_microchip);
    $chip_bean=implode($bean_solicitud->$rel_microchip->get());

    I get this error message in the log file
    Warning: Illegal offset type in isset or empty in /opt/lampp/htdocs/sugarcrm/data/SugarBean.php on line 975

    Notice: Array to string conversion in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75

    Notice: Undefined property: R2_Solicitud::$Array in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75

    Fatal error: Call to a member function get() on a non-object in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75
    (Line 75 is this one in my code $chip_bean=implode($bean_solicitud->$rel_microchip->get());)

    As the function is returning just the word "Array".
    If this function does not work.... How can I know how to call the relationships between two custom modules like 
    $bean_solicitud->load_relationship($rel_microchip);??????

    Thanks a lot!!
Reply
  • Hi there

    I have  a similar problem like you are managing in this post. I have created two custom modules with a one to one relationship

    R2_Microchip has a one to one relathichip with R2_Solicitud. I am builing a button in the DetailView of the R2_Solicitud module and this button calls a controller function that needs to take the related R2_Microchip and work with it.

    To do so i need to know the relationship between these two modules to be able to call it.

    I have found in this forum a post that points to  this blog

    http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-...

    However in my code, when I call this function this way

    $rel_microchip = getRelationshipByModulesgetRelacion("R2_Solicitud","R2_Microchip");

    $bean_solicitud->load_relationship($rel_microchip);
    $chip_bean=implode($bean_solicitud->$rel_microchip->get());

    I get this error message in the log file
    Warning: Illegal offset type in isset or empty in /opt/lampp/htdocs/sugarcrm/data/SugarBean.php on line 975

    Notice: Array to string conversion in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75

    Notice: Undefined property: R2_Solicitud::$Array in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75

    Fatal error: Call to a member function get() on a non-object in /opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php on line 75
    (Line 75 is this one in my code $chip_bean=implode($bean_solicitud->$rel_microchip->get());)

    As the function is returning just the word "Array".
    If this function does not work.... How can I know how to call the relationships between two custom modules like 
    $bean_solicitud->load_relationship($rel_microchip);??????

    Thanks a lot!!
Children