You have reached the last guide in our Appian Guide Series. At this point, you learned how to create interfaces, processes, and constants. It is time to use that knowledge to finish our vacation approval application. We will also look at expression rules and lists.
An expression rule is a stored expression that can be called from other expressions. Like functions, expression rules always return a value that may be influenced by one or more inputs. Rule inputs are used to pass data into the expression rule, just like function parameters. To create a new expression rule, navigate to the “New” dropdown and select “Expression rule”. Since we will use this expression rule to get all vacation requests that need to be approved, we shall name this rule “VAD_getVacationRequestsForApproval”. Just like when creating other objects, we need to populate description and select folder where the rule will be saved.
Once we have created the expression rule, we can design it to fetch all vacation requests that are not approved. We are using the following code:
a!queryEntity(
entity: cons!VAD_VACATION_APPROVAL,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "OR",
filters: {
a!queryFilter(
field: "isapproved",
operator: "<>",
value: true
),
a!queryFilter(
field: "isapproved",
operator: "is null"
),
},
),
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: a!sortInfo(
field: "id",
ascending: true
)
)
)
)
The function a!queryEntity is used to execute a query on a given data store entity and return the result. It is defined by an entity and a query. The constant VAD_VACATION_APPROVAL is a pointer to the vacation request entity defined on the database and is passed as an “entity” parameter.
In the function a!query we are creating a logical expression that holds query filters. These filters will determine which data rows will be returned from the database. A query filter has two main attributes: field and operator. Field determines which entity attribute will be targeted and the operator sets the condition for that attribute. Some operators (e.g. “=”) require a value for comparison.
The function a!pagingInfo is used to determine batches of data that will be returned. In our case, paging info is set to return all requests since we are dealing with a small data count. Also, we are sorting fetched data by using the a!sortInfo function. Our data is sorted by id, ascending.
You can click on the function name to read more about it in the official Appian documentation.
To create a list of all the vacation requests waiting for approval, we need to create a new interface. Follow the procedure as described in previous guides.
Once in the interface designer, search for the read-only grid and drag and drop it in the center of the canvas. Once the grid is rendered, the component configuration tab will open. For the data source, we need to use our previously created expression rule so we will select “EXPRESSION” and click “Edit”. In the query editor, we can reference our expression rule. It is important to reference only data from the expression rule: rule!VAD_getVacationRequestsForApproval().data.
Once we click “OK”, the designer will generate columns in our grid. Since we don't need all the data, we can remove some. Use the “Columns” section in the component configuration to achieve the design as seen here:
There are two columns that we need to configure. First, we want to display the user's first and last name instead of the email and we want to calculate the duration in workdays for the “Duration” column.
To display the user's first and last name, use the user function, and to calculate duration, use calworkdays, both as described in the previous guides.
To be able to finish the grid, first, we need to create a process for approving the vacation requests. The process will be similar to the one we have created in the previous guide. Take your time and try to create the process on your own as an exercise. Fear not, the whole process will be described in this guide.
We will start by creating a new process model.
Once the process is created, we can add a process variable which will be a parameter and will hold a request id. We will use that variable to fetch a vacation request from the database.
To be able to fetch the request, we need to create a new expression rule just like VAD_getVacationRequestsForApproval. In this one, we need a rule input. We can create one by clicking the “+” sign in the right upper corner. We need to set a name and a data type which will be an integer.
You can use this code in the expression rule:
if(
isnull(ri!vacationRequestId),
null,
a!queryEntity(
entity: cons!VAD_VACATION_APPROVAL,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
a!queryFilter(
fiel1d: "id",
operator: "=",
value: ri!vacationRequestId
)
},
),
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: a!sortInfo(
field: "id",
ascending: true
)
)
)
)
)
Now that we have defined the expression rule, we can add a script task to the process. On the “Data” tab, the “Outputs” subtab, create a new output variable. In the “Expression” section, we can reference our expression rule which will fetch the vacation request based on provided ID. To save the vacation request object, we can create a new process variable by clicking a “+” sign next to the “Target” section. Create a new variable of a VAD_vacation_approval type and click “OK”.
Now that we have a request, we can open our previously created interface for vacation approval (VAD_f_vacation_approval). Add the “User Input Task” node and open properties. Go to the “Forms” tab and select our approval form. Once the interface is selected, we are prompted with a question if we want to automatically generate variables according to the interface. We want to click “Ok” because the process will automatically generate all the necessary variables required for our interface to work. Go to the “Data” tab and check the node input configuration.
Also, we need to set the assignee for the task. We will use the person who initiated the process.
To be able to save the vacation request, we need to use the “Write to Data Store Entity” node. It needs to have the same configuration as in the previous guide.
In the end, we need to enable activity chaining on the process so we can interact with the application while the process is active. Now just save and publish the process model.
Now that we have our process model, we can start it from our grid interface. First, we need to create a constant which will reference our process model. In the window for creating a constant, select the process model and choose our Vacation approval process.
Now we can add another column at the end of the grid which will be used to start the process. In the “Columns” section on the interface, select “ADD COLUMN”. Next, switch the designer to the expression mode and use the following code to display an arrow icon:
a!gridColumn(
label: "",
value: a!imageField(
images: a!documentImage(
document: a!iconIndicator(
icon: "MOVE_RIGHT"
)
),
size: "ICON"
)
)
To start a process by clicking on the arrow, switch back to the designer mode and navigate to that column in the grid. Click on “Image” and then on “Document Image.” In the section “Link”, select a new “Start Process Link” and click on the created link. Once in the link properties, select a vacation approval process model. In the section “Process parameters”, click “Edit” and enter the following line: {vacationRequestId: fv!row.id}. This means that for every vacation request in the grid, a process will start with the parameter “vacationRequestId” having the ID value of that request.
We are almost done! We just need to create a report that will display our list and place that report on the homepage. To create a new report, navigate to the “New” menu and select Report. Give the report a name and the description and select our list interface. Configure report security and click “OK”. Also, we need to create a constant so we can reference the report later on the homepage.
Open our homepage interface and duplicate the existing “Vacation Request” card. Once the card is duplicated, we can change the icon and the text. Also, on the card component, we need to delete the old “Start Process” link and create a new “Report” link. To do so, navigate to the “Card layout” and delete the “Link” section. Once the link is deleted, we can create a new “Report” link which will open our list interface.
Now, all we got to do is test the application.
Thank you for being a part of this exciting journey, from the creation to the competition of the application. Thank you for your time and interest. I hope we have brought you closer to Appian as a platform. Our Appian experts are always at your service.