Add company address contact

See also: Addresses, Contact type, Address (Events), 'Add as company contact' button

Event action – Abstract

Purpose: Assigns an address present as a reference object to a company account as an address contact with a specific Contact type.


images/download/attachments/189439250/image-2024-11-25_15-54-20-version-1-modificationdate-1732546459869-api-v2.png

The Adresse als Kontakt einer Firma hinzufügen event action can be performed with an entity of the 'Address' type as a reference object. This action can be used to assign the address to a company account (see Company accounts) as an address contact with a specific Contact type.

The following rules apply:

  1. An address is added only if it is not previously assigned as an address contact for the same Contact type within the address of the company account.

  2. Unless the Contact type in the dynamic enumeration qualifies as 'plural', an added address contact replaces an existing one for the same Contact type.

NOTE

  • Adding an address as an address contact for the Target company implies saving the relevant company account if its address does not yet contain the combination of address ID and Contact type (see rule no. 1 above).

  • For the account of the Target company, either the 'Change' (existing company account) or 'Create' (new company account) event is triggered when saving.

  • If the relevant access rights ('Change' or 'Create') for the account of the Target company are missing, the event handling will cancel with an error (incl. rollback).

  • If there is no suitable value for at least one of the Contact type or Target company parameters (see 'Configuration') at runtime, the event handling will cancel with an error (incl. rollback).

Special application case:

In Input forms, the Button "Als Kontakt der Firma hinzufügen can be used to trigger the 'Add address' event ( 'Address' form element) for a 'Company and address attribute' in the context of an address search (see Address (Events)).

This button can be used if the address search via Combobox deviates from the default and does not refer to addressbook entries but to address contacts of a certain company. The link to the company must be established at runtime via the Use contacts of this company action. Usually, this happens as a reaction to the selection of the company in another Combobox element (for details see the 'Add as company contact' button).

The event primarily passes the relevant address as an input value. In addition, further data from the call context is provided in variables:

Variable name

Data type

Content

contactCompanyId
Long

ID of the company whose address contacts were offered in the form in the Combobox for the address search.

contactTypes

Contact type list

List of all contact types selected as relevant in the service configuration for this Combobox.

contactType

Contact type (ContactType)

The first entry (Contact type) of the list in the variable contactTypes.

Provided that exactly one relevant Contact type is selected in the address search, the variables contactType and contactCompanyId can be transferred directly to the Contact type and Target company parameters in the event action Adresse als Kontakt einer Firma hinzufügen.

If the address search refers to more than one Contact type, the event handler must make a determination or – if necessary, taking into account the list in the contactTypes variable – query the user (see 'Special application case' example below).

'Address contact' background

An address contact (addressContact) is a typed attribute that is only offered for Addresses (see also 'Address contact' form element). Each address contact must be assigned a (sub)type from the dynamic enumeration Contact type. Depending on the 'plural' option for the Contact type in the dynamic enumeration, it can occur only once or multiple times in the same address. The value of an address contact attribute is the embedded 'address' (address) in the field of the same name.

IMPORTANTAddresses are handled in Lobster Data Platform / Orchestration as Referenced objects whose ID changes when address characteristics change. An address contact added via the Adresse als Kontakt einer Firma hinzufügen event action refers to a specific address ID and thus a specific combination of characteristics for address data. If the address to be added is 'read' from an existing data object, no link to this origin object is created. Changes to the address data in the origin object therefore do not affect a created address contact, but change the address ID in the origin object, while the address contact continues to refer to the original address ID until address details are changed by accessing the address field in the address contact. Operationally, the event action Adresse als Kontakt einer Firma hinzufügen therefore acts similarly to adding a snapshot of the address from the origin object as an address contact.

Configuration

IMPORTANT◄ The address added to a company account as an address contact must exist as a reference object for the event action. Unless the event handling is executed as a whole with an entity of the 'Address' type as the input value, a context with a suitable reference object must first be defined for the execution of the event action. This allows e.g. event actions like Execute with or if necessary a For each loop over a list of addresses.

  • One of the values of the dynamic enumeration Contact type or a string corresponding to the internal name of one of these values must be specified as the Contact type. A static assignment per selection field may be possible using the value resolver 'any dynamic enumeration' from the category Static values.

  • The value resolver for the Target company can either return an entity of the 'CompanyAccount"(base:CompanyAccount) type or alternatively an integer (Long) corresponding to the ID (id) of an existing company account for which there must be at least read access.

NOTE◄ If there is no value or an unsuitable value for at least one of these parameters at runtime, the event handling terminates with an error message (and rollback if necessary).

images/download/attachments/189439250/image2021-5-6_15-29-18-version-1-modificationdate-1732545977715-api-v2.png

Examples

General application case

In a B2B portal implemented with Lobster Data Platform / Orchestration, the operator would like to create and manage company accounts for its business customers for logging into the portal. The administration of these company accounts is the task of 'account managers' at the operator, for whom a separate role 'CustomerAccountManager' has been set up for this purpose.

When saving (creating or modifying) a company account by a user who uses the 'CustomerAccountManager' role, the address from his user account should be automatically added as an address contact in the company account in question. The Contact type 'Account manager' (with the internal name ACCOUNT_MANAGER) is specified, which was created especially for this purpose. There should always be exactly one 'account manager' responsible for each customer. An existing address contact for the Contact type 'Account manager' should therefore always be replaced if a different address is added for the same Contact type.

NOTE◄ For a practical application, it is important to take into account that the address in the added address contact matches the address in the user account only until an address feature is changed (see 'Background' infobox above). If the address in the user account is changed after the address contact has been added, the address ID referenced by the user account changes, while the address contact still references the original address ID and displays its data unchanged. An update or synchronization would require additional precautions.

Runtime example:

The user 'Karola Mustermann' is logged in for the portal operator (Xflow AG) as 'CustomerAccountManager' and accesses the company account of a customer company via the 'Companyaccount overview:'

  • In the Contacts tab, the address contacts of the company are listed there. So far, the list of contacts refers only to the 'CEO'.

    NOTE◄ The form layout in the image on the right has been slightly modified compared to the default. Among other things, the symbol images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/forbidden.svg for deleting entries is hidden. Instead, a Delete Button has been added inside the repeated container for the address contact. This can be set active or inactive depending on the contact type to allow or prevent deletion (see Remove element (optional/repeatable element)).

    In the present application case, an address contact with the Contact type 'Account manager' should not be able to be deleted and should also appear deactivated except for the Button for 'e-mail' sending (see screenshot below right).


images/download/attachments/189439250/image2021-5-6_15-38-28-version-1-modificationdate-1732545977710-api-v2.png

As soon as the processing of the company account for 'fast-or-furious Ltd.' is completed via Save (in the ribbon), 'Account manager' appears in the company account, which shows the address for the user account (see Users) of 'Karola Mustermann'.

Only the name fields are displayed here, but the address contact provides access to the entire address, so that, for example, the e-mail function, can use the communication information it may contain.

images/download/attachments/189439250/image2021-5-6_15-39-11-version-1-modificationdate-1732545977708-api-v2.png

Configuration:

An event handler is created for the 'registration' of the user making the last change to a company account and configured as shown on the right:

  • 'Update' and 'Create' events (see Common action event) are set as the Triggering events.

  • The Validating rule uses Check type to determine whether the input value is the 'CompanyAccount' type. If this is the case, the AND-junction Sub criterion rule is evaluated, which determines per Role rule whether the 'CustomerAccountManager' role is claimed in the logon context.

images/download/attachments/189439250/image2021-5-6_15-40-56-version-1-modificationdate-1732545977705-api-v2.png

  • An Action on passed rule is an event action of the Execute with type that is used to define the reference object differently from the company account that is the input value:

    • The company account from the input value is saved per Save Company account in variable parameter in a variable with the name company .

    • In the Object Resolver, the User of session is first determined via concatenation and then the associated user account is read via an Input object (type safe). In the address field, the address contact that is added for the 'customer advisor' can be found. This is valid for the following action block as a reference object.

  • In the Execute with event action block, the only event action that follows is Adresse als Kontakt einer Firma hinzufügen with the following parameters:

    • As Contact type, 'Account manager' is assigned as a static value (per 'Any dynamic enumeration' value resolver, see Static values).

    • Access to the Target company, which is the input value outside the Execute with event action, is available within the Execute with event action only via the Variable company .

NOTE◄ The fact that the Target company is also the input value of the event handling is a coincidence. If the address of 'Karola Mustermann' in our example is not yet entered as an address contact of the 'Account manager' type, the 'Update' event for the company account will be triggered twice, because the address contact is added again.

images/download/attachments/189439250/image2021-5-6_15-42-20-version-1-modificationdate-1732545977703-api-v2.png

Special application case

The following example demonstrates the use of the Adresse als Kontakt einer Firma hinzufügen event handling in connection with the 'Add as company contact' button triggering event 'Add address' (see Address (Events)).

In the course of addressing a shipment, a company account is selected for the company and address attribute Loading party (Company type DPA) initially in order to be able to specify a precise pickup position (here: Loading party Address), which, if necessary, will subsequently be stored in the address of the same company and address attribute.

When selecting the company for the Loading party, the action Use contacts of this company for the Combobox of the Loading party Address is executed in the entry form. In the example, this should then offer all address contacts with the Contact type 'Gate/Entrance' or 'Building' for selection, which are found in the company account of the selected company.

Alternatively, a completely new Loading party address can also be entered.

Via the 'Add as company contact' button, a newly entered or changed company address should be added as a contact. The user should be able to define the assigned Contact type for the address contact via context menu (see screenshot on the right) from the options relevant for the pickup address.

images/download/attachments/189439250/image2021-5-6_15-45-50-version-1-modificationdate-1732545977700-api-v2.png

Configuration:

The configuration of the collection form is not described in detail here. To understand the event handling configuration described below, it is only relevant that the service configuration for the Combobox element within the Loading party Address names the Contact types 'Gate/Entrance' and 'Building'. Therefore, only addresses referring to address contacts of the selected company belonging to one of these two types will appear in the dropdown for selection.

images/download/attachments/189439250/image2021-5-6_15-48-15-version-1-modificationdate-1732545977698-api-v2.png

Therefore, when the 'Add as company contact' button is used to trigger the 'Add address' event for the Loading party Address, the contactTypes variable contains a list with these two contact types.

For the Triggering event 'Add address' (see Address (Events)) the event handling shown on the right is configured:

  • The Validating rule uses Check type to ensure that an 'address' was passed as the input value. When triggering the event by the 'Add as company contact' button, this should be implicitly guaranteed. So the Check type here essentially declares the data type 'address' for the input value.

    NOTE◄ The event is defined here in a generic way and therefore does not need any further rules for the transferred 'address' or the values of the variables that are automatically filled when the event is triggered (contactCompanyId, contactType und contactTypes).

  • Therefore, among the Actions on passed rule, it is first determined whether the Contact type to be added to the company account is uniquely determined by the context. In the Object Resolver, the Execute with event action defines the Contact type list in the contactTypes variable as a different reference object for the following block of event actions:

    • An If then else event action examines the field length of the list by an Entity property rule to determine if it contains more than a single element. The user should only have to select from the available options via the context menu if this is the case.

    • If a decision is required, the Show context menu event action displays the localized texts for the contact types contained in the list as options.

      • Since the list is already available as a reference object, the Object property value resolver inserted under Root items gives the entire list without a field.

      • The label expression accesses the Localization with the syntax [bundle, resource] to look up the localization entry for the name of the respective contact type (resource {name}) in the bundle de.lobster.scmbase.address.attributes.ContactType there.

      • The contactType variable is specified here as the Name of result variable. This variable contains the first value of the list until the context menu is called, because the 'Add address' event automatically preassigns this variable.

      • The selection in the context menu returns the Contact type clicked on, unless the user allows the Wait time (set here to 300 seconds) to elapse or closes the context menu without making any selection (via the Esc key or by a mouse click in the form.

NOTE◄ The already pre-assigned variable contactType is also specifically selected here as the target for the return object of the context menu, so that within the event action Adresse als Kontakt einer Firma hinzufügen for the parameter Contact type the value of the variable contactType can always be transferred. In the special case of a crash or timeout after opening the context menu, however, the Adresse als Kontakt einer Firma hinzufügen event action is then blocked from being executed at all, otherwise 'no value' is passed as Contact type, which leads to a crash with an error message (incl. rollback).

images/download/attachments/189439250/image2021-5-6_15-50-40-version-1-modificationdate-1732545977695-api-v2.png images/download/attachments/189439250/image2021-5-6_15-52-21-version-1-modificationdate-1732545977679-api-v2.png

After completion of the Execute with event action, which is only relevant if the Contact type is not uniquely predetermined, the address to be added is again considered the reference object. In this context, the event action Add company address contact is executed:

  • Within an If then else event action, however, it is checked beforehand whether the variable contactType is empty:

    • If the variable specifies the predetermined or selected Contact type, then the event action Add company address contact is executed, assigning the variable contactType as the Contact type and the variable contactCompanyId as the Target company.

      NOTE◄ If there is no permission in the logon context of the session to change the company account in question, the event action should be executed within an Run as event action with a different logon context.

    • Without any specification for the Contact type – i.e. if the user has exited a context menu without any selection – the event handling should be terminated without comment or further event actions.

images/download/attachments/189439250/image2021-5-6_15-54-3-version-1-modificationdate-1732545977674-api-v2.png