Using Extension Points in Now Experience Declarative Actions



I walked through adding an 'Add' button in Agent Workspace in a previous post, but get questions from time to time on how to filter the records that are displayed in the modal to select from. This post will focus on how to do this for Now Experience Workspace, it can be done for Agent Workspace, the setup is different for Declarative Actions between the two, but calling the Extension Point should be similar.


The answer is in the product documentation but it can be difficult to locate, especially if you don't know the terminology or are trying to do a search. In this post, I'm going to walk through adding an 'Add' declarative action in a Now Experience workspace, and filtering the displayed list by calling an Extension Point in the extensionPoint field in the Action Payload Definition.


I'll skip over the application setup, but basically I just created a scoped application that extends Case that I use in my demos. Nothing special has been done to this table, I just created an app in App Engine Studio called Scoped Case, created a table extended from Case called Scoped Case, and created a Workspace experience within this app in App Engine Studio and set the primary table as Scoped Case, then added some demo data in. I then added the following related list 'Scoped Case > Parent' to the OOTB Workspace view.


Note: I noticed that the 'Record default' variant uses the 'Default' view of a record, but creating a copy (not read only) of the Record page uses the 'Workspace' view OOTB. I'm sure more can be done to control views, but if you're exploring OOTB configuration this is something to be aware of.


Here's a rundown of what we're going to do:

  1. Create an Action Payload Definition

  2. Create an Action Assignment

  3. Create a UX Add-on Event Mapping

  4. Create an Extension Point

The outcome is that we're going to have an Add button on our custom table, that launches a modal window, with only the Scoped Cases we want to see per the extension point filter.


Action Payload Definition


I'm starting with this first because it's a mandatory field on the Action Assignment form, so I wouldn't get very far without it. I thought I could re-use 'Add Related Item Requested' but upon digging deeper, it's specific to Case, so I'm going to set up my own Action Payload Definition - sys_declarative_action_payload_definition. At this point in time, there's no specific product documentation on if this is the correct way to do this, if I should be doing it, etc. so things can change as time goes on, but for exploratory purposes, I'm going to create this.


I performed an Insert and Stay on the ADD_RELATED_CASE_REQUESTED Action Payload Definition, and configured it as such, which automatically set up the Action Payload Mappings and Action Payload Fields for me, and modified the table to point to my Scoped Case table instead. The Payload controls what is placed in the mapping and fields, so as long as you update/save your Payload the related lists items will update accordingly. I do want to point out the 'Applicable To' list, I've poked around and some actions can be set for both List and Related List, just know this field needs to be set and controls where your action will be displayed.



One thing to note, is if you're working with Agent Workspace Declarative Actions, you'll find these fields under the Component Attributes tab, for more information on setting up Agent Workspace Declarative Actions, see my post here.


Action Assignment


I'll preface this with that it seemed easier to me to create Related List Actions for Agent Workspace, but I'm trying to move away from configuring for that and jumping into Now Experience Workspace only. I did some poking at the CSM Configurable Workspace to see how ServiceNow achieved this. I recommend installing this plugin on your PDI as a guide and template for Now Experience Workspaces. You can use the Workspace modules to get here, for reference the table is sys_declarative_action_assignment.


I'll implement this button as a UXF Client Action, instead of a UI Component (used for Agent Workspace) and linked up the Action Payload Definition I created above via the Specify client action field.



UX Add-on Event Mapping


I spent quite some time clicking on my button and having nothing happen before I started adding related lists on the Action Assignment form for other actions. I discovered that an event mapping has to be created in order for the 'click' to actually do something. You can add the related list or visit the table sys_ux_addon_event_mapping to add this record.


To make it easy, I just performed an Insert and Stay on the Add Affected Install Base mapping, and changed the name to Add Scoped Case, and re-pointed the Source Declarative Action field to my Action Assignment.




I'll do a quick test now to make sure my button is working and showing all Scoped Cases before configuring an Extension Point. Clicking on 'Add' in the Scoped Cases related list on my Scoped Case record brings up the modal window, and shows the fields defined.



Extension Point


Now we'll go in and filter out the Scoped Cases that have a Product of 'Acer Notebook Battery' via creating an Extension Point and adding it to the Action Payload Definition.


The Extension Point we're going to be working with is called RelatedListItemCandidateFilter which is located under System Extension Points > Scripted Extension Points. I clicked 'Create implementation' and set the Script include to be called by All application scopes. If you look at something like the CasesRelatedListItemCandidateFilter, it has a lot in it for Install Base, I suggest looking at the ProblemRelatedListIncidentFilter as a more simplistic example to go off of.


Here's the script include I created, I copied an encoded query to state Product is not Acer Notebook Battery (represented by the sys_id), to note, I did not keep the same name as the parent extension point as to not confuse/override values.


var ScopedCasesRelatedListItemCandidateFilter = Class.create();
ScopedCasesRelatedListItemCandidateFilter.prototype = {
   getFilterQuery: function() {
      return "product!=26431e62ac10a501177f7cd98f0de15e";
   },

   handles: function(thing) {
      return thing == "SCOPED_CASE_FILTER";
   },
   type: 'ScopedCasesRelatedListItemCandidateFilter'
};


I'll now add the extension point to the Action Payload Definition, you can see in the extensionPoint field, I don't call the API/Script Include name, I add what it returns, i.e. SCOPED_CASE_FILTER



Clicking on the Add button in the Scoped Cases Related List, I now see that the Scoped Case with the Product of Acer Notebook Battery is no longer available.



I'm sure these conditions can get way more complex than just excluding specific sys_ids, I recommend installing the CSM/FSM Workspace plugins in your PDI to get some examples and hope this post shed some light on how to create a simple 'Add' Declarative Action in Now Experience Workspace, and control what shows in the list by using Extension Points.


Resources


Set up adding records to a related list (Agent Workspace)


Using extension points to extend application functionality

181 views0 comments

Recent Posts

See All