Exercise 3: Field Decorator Declarative Action
Declarative actions add custom functionality to your Workspace forms, fields, lists, and related lists without writing custom scripts or learning APIs.
Goalβ
In this exercise, you'll add a field decorator declarative action. In the HR Agent Workspace, you have a requirement to add a field decorator (icon button) to the HR Service field that will pop open a modal showing the most recent 10 cases opened in that category.
There are a few ways you could solve this problem of getting more context around what people are asking related to a specific service, and this exercise will teach you how to solve it with a declarative action.
Add Demo Dataβ
You'll need to create a quick case for demo data.
-
In the platform view, go to Workspaces > HR Agent Workspace.
-
Click on the plus sign and create a new HR Case.
-
Choose Skip verification and fill out the form:
-
COE: HR Case
-
HR Service: General Inquiry
-
-
Click Create Case.
-
Create a second case.
Build the modal and event in UIB
Create a new record page variantβ
-
Open UI Builder (UIB) by going to All > UI Builder or click the icon at the top left of the UIB window to get to the UIB homepage.
-
Open the HR Agent Workspace experience.
-
Switch your scope to the Agent Workspace for HR Case Management.
When duplicating a variant you want to do it in the same scope as the original variant.
-
Scroll down to the Record page and, mouse over Case SRP, click the three vertical dots icon to the far right, and choose Duplicate Variant.
-
Name the variant Case SRP Acme copy and click Create.
Since you're duplicating the page and owning the new variant it's probably helpful to come up with some sort of naming convention to easily tell your variants apart from the ServiceNow shipped pages.
-
Click the Settings pill at the top of the page, change the order to 0, and click the Save button.
-
Switch back to the editor view and give the page some test values by clicking the table pill just under the experience name at the top of your window.
-
Set the table required parameter to sn_hr_core_case, let the sysId auto-fill, and choose Apply.
You'll now see some of the components appear in the middle of the page since they've got data.
-
Save the UI Builder page.
Add a modalβ
Now you'll add a new modal to the page that will show a list of related records.
-
In the content tree, mouse over modals toward the top under Overlays, choose the plus sign to the right, and choose Custom.
-
Rename the modal by clicking the
(i)
icon next to Custom 1 in the right-hand panel to the following:-
Component label: Related cases modal
-
Component ID: related_cases_modal
-
-
Click Apply.
-
Collapse all the modals in the content tree on the left except for your new modal, and click +Add component under the Heading 1 section of your modal.
-
Add a Stylized text component.
-
Remove the preset using the preset dropdown on the config panel and clicking Remove in the popup.
-
Change the Text property to data binding.
-
Choose the Formulas tab and the CONCAT formula.
-
Double-click into value1 and type "Related records for " (with the quotes)
-
Now click into the second value, click into the Data types tab, and choose Data resource > record > form > fields > hr_service > displayValue, and choose Apply.
-
In the Body 2 section in the content tree, choose + Add component and add a List - Simple.
-
Choose None for the preset to configure it manually.
-
Configure the component's properties in the Configure panel as follows:
-
Table: HR Case
-
Edit fixed filter:
<data binding>
HR service | is | Data resource > record > form > fields > hr_service > value -
Columns:
<add one at a time>
-
Number
-
Subject person
-
Description
-
-
Maximum rows: 10
-
-
Now add a Button component to the modal's footer.
-
Remove the preset.
-
Change the button's label to Close.
-
Click into the Styles tab and give the button a margin of L.
-
Click into the Events tab and choose Add Event Handler.
-
Choose Open or close modal dialog.
-
Choose the Related cases modal for the Modal and click Add.
-
Save the UI Builder page.