Using Entity with Date and Time Functions
This post describes two major activities related to the configuration of functions under the Date and Time category. The first activity includes steps to create an entity that contains values in date and time formats. The second activity describes how to use the entity in the date and time functions when you want to fetch the data from the entity.
In date and time functions, you can use an entity when you do not want to define the date and time by using the Static function. These two activities are broadly described as below:
Creating a New Entity
If you plan to fetch the data from an entity when a Date and Time function (for example, ADDYEARS, ADDSECONDS) is executed, you need to create an entity and then define required attributes in the entity. When you define attributes, you need to define values of the related attributes. When a Date and Time function (for example, ADDYEARS) is executed, it fetches the data from attributes in the entity and then returns the result.
To create a new entity:
On the current page, see the top panel.
- In the top panel, click the VDLC icon () to expand the VDLC menu.
- On the VDLC menu, point to Design & Architecture and then click Data Modeler to display the Data Modeler page.
- On the Data Modeler page, click the Create Entity link to display the Create Data Entity dialog box.
- In the Create Data Entity dialog box, do the following:
- In the Key box, enter the name of entity (for example, ent_dateandtime).
- Click the Entity Type list and then select Business Entity.
- Click Create to create the entity.
Defining Structure of Entity
After you create a new entity, you can search and find it under the Entity tab. After you find the entity under the Entity tab, you can define the JSON structure in the entity as follows:
To define the JSON structure:
- Under the Entity tab, see the list of entities:
- In the list of entities, search and find the entity (for example, ent_dateandtime)
- After you find the entity, click it to display the <<entity name>> page.
- On the <<entity name>> page, click the Edit icon () to enter the JSON code in the Input box.
#Sample JSON Code for Date and Time Functions:
{ “ent_datetime”: { “date”: “05/03/22”, “time”: “2:10:34”, “int”: 3 } } |
- After you enter the JSON code in the Input box, click the Format icon () to beautify the JSON code.
- Click the right arrow icon () to create the output in the Output box.
- Click Save to successfully define the structure of the entity.
In the JSON code:
- The date attribute contains a date, 05/03/22. When a date type function (for example, ADDYEARS) is executed, it will replace the date parameter from the 05/03/22 value.
- The time attribute contains a time, 2:10:34. When a time type function (for example, ADDMINUTES) is executed, it will replace the time parameter from the 2:10:34 value.
- The int attribute contains an integer value, 3. When a date type function (for example, ADDYEARS) is executed, it will replace the years parameter from 3. When a time type function (for example, ADDMINUTES) is executed, it will replace the minutes parameter from 3.
Result After Execution
- Case1:- When you map the ent_datetime entity in a date type function (for example, ADDYEARS), the ADDYEARS function will add 3 to the date, 05/03/22, and then it will return the 05/03/25 (5th March, 2025) value.
- Case2:- When you map the ent_datetime entity in a time type function (for example, ADDMINUTES), the ADDMINUTES function will add 3 to the 2:10:34 time, and then it will return the 2:13:34 (2 hours, 13 minutes, and 34 seconds) value.
After you successfully create an entity and define its valid JSON structure, you need to link the entity to a data model. To link the entity to the data model, see the Linking Entity to a Data Model section in the “The Concept of Data Model” post. To access the “The Concept of Data Model” post, click here.
Mapping Entity to a Date Type Function
After you define the JSON structure of the entity and then link it to the data model, you can map the entity to the date and time functions. When you map an entity to a date and time function (for example, ADDYEARS), you map the attribute in the entity. When a function executes at the runtime, it fetches the value from the mapped attribute.
- Click in the smart selector to display the Search box.
- In the Search box, enter addyears to display the ADDYEARS function.
- In the list, select the ADDYEARS function.
- In the ADDYEARS function, click the date parameter to display the Search box.
- In the Search box, click the Attribute tab, and then enter the attribute’s name (for example, date) in the Search box.
- After the smart selector displays the name of the attribute, click to select the attribute.
- In the ADDYEARS function, click the years parameter to display the Search box.
- In the Search box, click the Attribute tab, and then enter the attribute’s name (for example, int) in the Search box.
- After the smart selector displays the name of the attribute, click to select the attribute.
When the ADDYEARS() function is executed, it adds the value stored in the int attribute to the value stored in the date attribute and then returns the date as a result.
Map Entity to a Time Type Function
You can map an entity to a time type function by following steps that you perform to map it to a date type function. See these steps in the section, Map Entity to a Date Type Function.