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.
What is necessary in the backend
In a nutshell:
- 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 - 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
- The relevant methods are
OnAfterFetchDynamic
andOnDatasetGenerate
, as described above - This EntityEventHandler should be included in the DSO as the attribute
ServerEventHandler
. In addition, the attributeresourceName
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
- 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
SimpleSwatDynamicControl
as an instance of the corresponding grid. For this control to work with your created DynamicFieldsDefinition, add this to the attributedefinitionBuilderClass
of theSimpleSwatDynamicControl
, 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 aStaticObjectB
(Included fields:StaticObjectID
,StaticObjectDescription
) and you want to add a SwatSelect to a screen ofDynamicObjectA
where the user can choose aStaticObjectB
via the description. Then you have also to add the fieldStaticObjectDescription
to theDynamicObjectA
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 fromStaticObjectB
to the new fields inDynamicObjectA
. Use theOnAfterFetch
method for that - I want to add the attribute
Mandatory
to my DynamicObject, but it is not working - Use
required
instead ofMandatory
this will be mapped to the correct value
Back to Documentation
Back to Home Page