Logo

    Home

    Documentation

    Use Cases

    Training

    Applications

    Release Notes

    Dynamic objects Sample: Explanation

    Dynamic objects Sample: Explanation

    Introduction

    This documentation explains the B1 sample “Dynamic Objects” which is included in the Sample Screen SampleUserDynDialog

    What you see in the UI

    If you open up the Screen SampleUserDynDialog, you’ll see a grid with users. Additionally, you’ll see (among others) two columns Deutsch and Englisch, which represent the system languages and as such, the translation of the username in this specific language. These columns are dynamically added to the user grid, if there are entries in the corresponding language table.

    You can add a new language to see that this is also added to the grid: Go to Manage → Grunddaten → Lang → Add a new language by using the FAB (Floating Action Button).

    After creating the new language and launching the SampleUserDynDialog again, you’ll see your new language in the grid. Like this, you can observe that this object builds dynamically at runtime.

    ⚠️
    Currently sorting and filtering is not supported for Dynamic fields in a grid

    What is necessary in the backend

    In a nutshell:

    1. Create an EntityEventHandler for your entity with the newly created event OnDatasetGenerate, for dynamically adding additional fields to your origin entity
      • In the OnAfterFetchDynamic event of this EntityEventHandler, you can manipulate the data, e.g., changing names of the datafields
    2. Additionally, you’ll create a DynamicFieldsDefinition, which also adds the dynamic fields of the entity to the grid

    Create an own EntityEventHandler

    • Here you’ll find the sample code for the EntityEventHandler written in ABL - file name UserEntityEventHandler.cls
    • ‣
      Expand here for Code
    • The relevant methods are OnAfterFetchDynamic and OnDatasetGenerate, as described above
    • This EntityEventHandler should be included in the DSO as the attribute ServerEventHandler. In addition, the attribute resourceName must be suffixed with :dynamic to tell the backend that this DSO must not be cached and will always be created when a user requests this, e.g., Akioma.Swat.OERA.Dynamic.SwatDynamicBusinessEntity|SampleUserDynDSO:dynamic

    Create an own DynamicFieldsDefinition

    • Here you’ll find the sample code for the DynamicFieldsDefinition written in ABL - file name UserGridDynamicFieldsDefinitionBuilder.cls
    • ‣
      Expand here for Code
    • This class creates an array (oFieldsArray), in which all the additional columns are added. Afterwards, this array is added to the grid as sibling columns.
    • To include this DynamicFieldsDefintion, add a SimpleSwatDynamicControlas an instance of the corresponding grid. For this control to work with your created DynamicFieldsDefinition, add this to the attribute definitionBuilderClass of the SimpleSwatDynamicControl, e.g., Akioma.Swat.Samples.CustomDefinitionBuilder.UserGridDynamicFieldsDefinitionBuilder

    FAQ

    • How can I use a SwatSelect in a dynamic object?
      • You can use the SwatSelect the same way as you also use it in static objects. But keep in mind, that you have to add all the the fields you want to display from the referenced object also to the dynamic object.
        • Example: Let’s say we have a DynamicObjectA (Included fields: DynamicObjectID, DynamicObjectDescription, StaticObjectID) and a StaticObjectB (Included fields: StaticObjectID, StaticObjectDescription) and you want to add a SwatSelect to a screen of DynamicObjectA where the user can choose a StaticObjectB via the description. Then you have also to add the field StaticObjectDescription to the DynamicObjectA Therefore do the following:
          • Add this field to your data definition file, e.g. dsDynamicObjectA.i
          • Reference this file in your EventHandler, e.g. the DynamicObjectAEventHandler.cls and fill data in the field, by finding and assigning values from StaticObjectB to the new fields in DynamicObjectA. Use the OnAfterFetch method for that
    • I want to add the attribute Mandatory to my DynamicObject, but it is not working
      • Use required instead of Mandatory this will be mapped to the correct value

    Back to DocumentationDocumentation

    Back to Home Page

    Logo