What is the reference data type?
Reference data type is used to denote a row of a particular list.
For example, if I say I have a reference field of “employee list” and that field has some data assigned to it. This means that the reference field is denoting some row of “employee list”.
When we say data type, It often comes to our mind as a format of data with certain rules and standards. In general programming, we define the datatype of variables and then save the value assigned to it. Likewise for reference data type variables (fields), if there is no data assigned to the field that means it is not denoting any row of the particular list and vice versa.
Reference data type field with data assigned to it -> Denotes a row of the particular list.
Reference data type field with empty value ->Does not denote any row.
Structure of reference data type fields
When we define a reference data type field it requires a list associated with itself and a name.
For example, if I want a reference field of “employee list” I’ll select that list whenever I’ll be defining the reference field. Like all the fields you also need to provide a name for the reference field.
If I have to define one reference field of “employee list”. I’ll write the name of the field as “employee” and select ”employee list” as the associated list.
How to get row data from reference fields
We can get any data of the denoted row of the “employee list” using the “->” operator.
For example “employee list” has multiple columns like employee name, employee no, employee activity status etc. If I want to access the employee name then I can just write an expression like employee(reference field) -> employee name and it will fetch the employee name. If the field is empty then you won’t get any data. (if you are wondering how to assign data to a reference field then I should let you know that part will come later.)
Before learning how to assign data to a reference field we should understand the concept of Row positioning.
Row positioning is clearly defined as the selected row of a list. It is also referred to as the current row of the list in WEM.
Row positioning is dependent on many events which are listed below
Datagrid click(row click, button click inside the row)
Repeater click (div, button)
List action node(add, go to first node, go to next node, reset row position, go to last node, go to previous node)
Loop node (on each iteration of loop row position changes)
Note: If you navigate to a different page using the navigation menu the positioning will be reset which means there will be no row for the current position.
Assignment of reference field
Step 1: Set the row position using above listed events in the “row positioning section”.
Step 2: Select field as assignment node in the flow and then for that node choose “set to current row” option
Eg: let’s say I have a reference field of the employee list named “Emp”. I need to find an employee using employee ID and get the reference and assign it to the reference field “Emp”.
We will take a list action node. Select the “goto first row” action. Apply condition for “goto first row that matches”. The condition will be that the employee ID you want to match should be available in the column of employee ID in the employee table. So we can write something like employee ID field from input = employee ID column of employee table.
What is rowid() function and how to use function rowid()
Whenever you try to print an assigned reference field you will get to see some ID similar to i15843779_1 called reference ID. So whenever you try to use rowid(List) and try to print, It will give you a reference ID. What it actually means is rowid() can give you a reference to the current row of a list.
The question that arises here is, if I can get the reference using the “goto first row” action of list action node, why would we need rowid()?
So the answer is when we use reference fields and assign them with the current row, then It holds the position of the row despite the current row position change throughout the session until it gets updated. So you can go to that row again by using a reference field. However, rowid() will always give you current row position reference.
So the choice here to make is if we do need to hold the reference for further use then we will use the reference field and if we don’t have to hold the reference we will use rowid(List)
We can use rowid() to match with the reference field to find the row. This comes handy in applying filters for datagrid and repeaters.
For example, I have clicked a row in the data grid of the Employee list and we have to highlight the row after that as a recently clicked row. How would we do it?
1. We will create a flowchart and set it to row click
Here “Row click” will be triggered on row click of the data grid
2. We will save the clicked row reference in a temporary reference field because we'll need that to match the clicked row.
Here Emp is the temporary field of the employee list.
3. We will apply filter conditions for highlighting the row. The condition will be rowid(Employee list) = Emp. Emp has a reference assigned to it. Here rowid(Employee list) behaves as a column of “reference” for each datagrid row. On printing, it will display “reference ID” as I have discussed earlier. So when you match Emp with a “reference” column it will filter out the clicked row and will highlight it.
In this blog we learned about reference data type, their structure, and how to get row data in WEM with the examples. We also learned the concept of row positioning and how to assign data to a reference field. I hope this blog will help you in clearing your doubts about reference data type.