How to use the 'showWhen' parameter of a SAIL component to choose one component or another, based off a user's interactions.
Try to follow these setup steps verbatim. However, if you do need to adjust any of these values, you'll need to ensure that you making the necessary modifications to SAIL recipes that depend on this data.
This example uses a custom data type. In an appropriate application, create anemployeecustom data type (leave namespace set to default) with the following fields:
id (Number (Integer))
Select the Key icon and set this field to Primary Key
click the Auto-generate checkbox to let the database handle value assignment
Next, let's create a data store within the same application where the CDT was created:
Create a new data store. Name the data store with a unique relevant name, like Employee DS.
Configure the data source to a data source you can access
In the data store, create a data store entity called employee
Set the data type to employee
Save & Publish the data store
Optionally, check the data base table to see that an employee table has been created
Finally, let's create constant within that same application so we can use the newly created data store in an expression:
Create a new constant. Name the constant EMPLOYEE_DSE.
Set the Data Type to Data Store Entity
Set the Data Store dropdown value to the Data Store created above
Set the Data Store Entity to Employee
Now that we've created the dependent objects and custom data type, let's move on to the main expression.
Test it out
Click the Publish Data button. The button will stay disabled and remain disabled as long as there is employee data present in the relational database table.
If data already exists in the database table, you should see a button that says, 'Data Already Published'
Notice the Id values went from all "N/A" to a sequential value
Notable implementation details
The a!forEach() function is used here to loop the dictionary of data into an array of employee data. If we were only writing one employee here or these values were coming from a cdt array (for example from a rule input of CDT array type) then a!forEach() is not necessary.
To avoid duplicate records, the button stays permanently disabled as long as data is present. If your interface did not need this restriction, removing the disabled parameter definition from the button would allow you to use this button again.
Two grids are configured in this example, but only one will ever show at a time. Instead of writing the logic in each of the grid text columns, we are showing a grid with hard-coded data when nothing is in the database table and the other grid when there is database data available.