Documentation

Accessing Accounts Data from Custom Objects

Available Liferay 7.4 U35+/GA35+

In some use cases, you may want to access account data from a custom object. For example, if you’re building a custom returns application, you may want to prompt users to select their desired account and postal address when creating a return request. In this scenario, users would need access to their existing account and address entries while in the returns application.

To achieve this, Liferay provides access to the Account and Postal Address applications in the Objects admin. Here, you can define relationships between them and your custom objects. Once defined, users can use the generated relationship fields in the custom object to select their desired Account and Postal Address entries.

Create relationships from the Account and Postal Address objects to your custom object.

Note

The Account object stores general account data (e.g., name, email), while the Postal Address object stores billing and shipping addresses for an account. Postal Address entries are created in the Accounts UI and are scoped to the individual account for which they’re created.

When relating a custom object to the Accounts and Postal Address system objects, these relationships should be defined on the system object side and use the one-to-many type. The custom object should be on the many side of both relationships.

Follow these steps to set up relationships for accessing Account and Postal Address entries from your custom object:

  1. Open the Global Menu (Global Menu), click the Control Panel tab, and go to Objects.

  2. Begin editing the Accounts object.

  3. Go to the Relationships tab and click the Add button (Add Button).

  4. Enter a Label and Name.

  5. For Type, select One to Many.

  6. For Object, select your custom object.

    Create a one-to-many relationship from the Account object to your custom object.

  7. Click Save.

  8. Return to the Objects admin page and begin editing the Postal Address object.

  9. Go to the Relationships tab and click Add (Add Button).

  10. Enter a Label and Name.

  11. For Type, select One to Many.

  12. For Object, select the same custom object as you did for the previous relationship.

  13. For Parameter, select the custom object’s relationship with the Account object that you created earlier.

    This is necessary because Postal Address entries are scoped to specific accounts. The parameter sets up a dependent relationship where available addresses depend on the Account relationship’s field value.

    Create a one-to-many relationship from the Postal Address object to your custom object and use the custom object's Account relationship as a parameter.

  14. Click Save.

  15. Add the relationship fields to the custom object’s default layout and view. See Designing Object Layouts and Designing Object Views for detailed instructions.

    Add the relationship fields to the custom object's default layout and view.

Once added, users can select from available accounts and addresses in the custom object. Available account options depend on the user’s account memberships, and available addresses depend on the selected account.

Users can select from available accounts and addresses in the custom object.

Tip

By default, objects use entry IDs for their title fields. The title field value determines how each entry option appears to end users in the relationship field. If desired, you can improve readability by configuring each object to use a different field for the title.

To do this, begin editing the desired object definition, go to the Details tab, and select a different value for the Title Field. Click Save when finished.

Additional Information