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
  • Ok, perfect, I found the problem. My relationship was empty, I thought it was Many to Many, but the field value I was searching for was in a related field and the relationship was actually One To One.
    Now I can retrieve all I need! :D
    Last question. How do I fill related fields in my Invoice with values I just retrieved?
    I have no problem on populate simple text fields, but is not the same for related fields.

    Thank you, you are saving my life!

Reply
  • Ok, perfect, I found the problem. My relationship was empty, I thought it was Many to Many, but the field value I was searching for was in a related field and the relationship was actually One To One.
    Now I can retrieve all I need! :D
    Last question. How do I fill related fields in my Invoice with values I just retrieved?
    I have no problem on populate simple text fields, but is not the same for related fields.

    Thank you, you are saving my life!

Children
No Data