Retrieve a user's partner company

Hi all,
Say « Chris » is a contact listed under Supplier « Top Supply ».

I need to retrieve the Supplier Company name, « Top Supply » via referencing Chris, and by using bean inject.

Will it be like
com.axelor.inject.Beans.get(com.axelor.apps.base.service.PartnerService.class).getCompanySet() ?
image - Error

com.axelor.inject.Beans.get(com.axelor.apps.base.service.user.UserService.class).getUser().getCompanySet() - Does not fetch anything.

com.axelor.inject.Beans.get(com.axelor.apps.base.service.user.UserService.class).getUser().getActiveCompany() - The company but not the Supplier. Not what I need.

Please advise.


All contact instances are associated with their respective partners, with the mainPartner attribute representing the ‹ supplier › in this case. To access the name of the main partner, you can use the following code: contact.getMainPartner().getName() which will return the name « Top Supply » for the contact named << Chris >> . Alternatively, you could execute a query to retrieve a list of contacts where the mainPartner is « Top Supply ».

Please let me know if you have any further questions or if there’s anything else I can assist you with.

Best regards,

Hi @sma-axelor ,

I am trying to use the App studio.
Is the following the correction method?
Can’t seem to fetch data out.

And I got an error, where « contact » is not defined.

Please advise.

Hello @AndrewTrust ,

I would like to clarify that the solution I previously suggested was intended for Java programming.

In reference to the statement provided by you in the forum post:

To address your question regarding how to achieve this using the object(named contact ) Chris, it is important to note that in the code snippet shared by me:

The variable contact represents the object referred to as Chris.

By invoking the getMainPartner().getName() method on the contact object, you can retrieve the name of the associated Supplier Company, which in this particular case is « Top Supply. »


If you prefer to implement this functionality in a view or using a custom field, you can utilize the expression self?.mainPartner?.name within the contact-form. or if you have the reference field to the contact (let’s say named as contactField) then you could get the supplierName using contactField?.mainPartner?.name
(Note: the question mark after field name is for null check. eg: it will only retrieve ‹ mainPartner › if ‹ contactField › is not null in contactField?.mainPartner?.name )

By incorporating the mentioned expression, you can retrieve the name of the main partner associated with the contact and display it accordingly. Please bear in mind that this method is limited to usage within the contact form or form which has contact reference as a field.

Should you have any further questions or require further clarification, please do not hesitate to ask.

Best regards,

1 « J'aime »

Hi @sma-axelor ,
Thanks for the detailed explanation and apology for lack of clarify in my first post.

Actually I am trying to build to use the App Builder and have seen some example script.
In most cases, the query is action-script and is based on javascript.

To access those function, i believe need to inject.Beans.get.
I managed to obtain user name, user company etc viat getActiveCompany(), and getUserPartner().

But searching through Axelor github, I couldn’t find any public function for getMainPartner().

Please kindly advise. Thanks.


The « getMainPartner() » is a getter method for « Partner » Entity. You can only use « getMainPartner() » if you have an instance of the « Partner » entity(in this case object referencing « Chris »). That is why I had suggested that you could only use the said method if you have a reference of the contact (« Chris »).

If you have any further questions or require additional clarification, please feel free to ask.

Best regards,

1 « J'aime »