How To Check Group Membership For SmartForms When They Load

  • 15 February 2022
  • 0 replies
  • 157 views

Userlevel 5
Badge +20
 

How to Check Group Membership When a Form Loads

KBS100024

PRODUCT
K2 smartforms
TAGS
How to Document
This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice. This article is not considered official documentation for K2 software and is provided "as is" with no warranties.
LEGACY/ARCHIVED CONTENT
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

Objective

In some situations, it may be necesary to check whether a user is allowed to view a SmartForm when they open it. The best method to do this is to checke whether the user is a member of a group that has been given permission.  This article is about how to check the group membership for SmartForms when they load.

Before You Begin

This KB assumes that you know the basics of SmartForm design. Additionally, it assumes that an AD Service2 Service Instance and its SmartObject have been created already on your environment to provide access to the full array of methods.

How-to Steps

1) To start with, create or edit the form where you want to check for group membership.

 

2) In the layout for the form, add a data label control which you will be using to check the membership. In the example below, it is called Group Data Label:

 

Image

 

Depending on the overall design of your form, you may want to set this data label to not be visible.

 

3) If there is already a rule for "When the Form is Initializing", edit this rule. Otherwise, create a new rule that uses "When the Form raises an event" as the event and choose Initializing as the event.

 

Image

 

4) As seen in the above image, you will add several steps to the rules to check to see if the user is a member of the required group. I would suggest that you add these before any other rules in order to minimize load times.

 

5) Add an "Execute a SmartObject method" action to the rules. 

 

6) Use the AD User SmartObject from the AD Service2 Service Instance as the SmartObject and GetUsersByGroup as the method.

 

7) Configure the SmartObject action.

 

😎 For the Input Mappings, input the name of the group, as seen below.

 

Image

 

9) Next, for the Filter, add a filter against the Name of the Current User in the System Values of the Context Browser.

 

Image

 

This will make it so only the name of the current user is returned. If the SmartObject call returns a value, then the user was in the group. Otherwise, the user was not in the group.

 

10) Finally, for the Output Mappings, transfer the DisplayName from the return properties to the Group Data Label that was created earlier.

 

Image

 

Which value is actually returned is not completely important. As such, any of the return values can be used.

 

11) You will then start adding the rest of the rules. To start with, add a condition to check whether the Group Data Label has a value.

 

Image

 

12) After this condition, you can then add an action to show a message to the user to tell them that they are not allowed to view the form.

 

13) Finally, add an action to stop the rule execution. This is important, as it will prevent the rest of the form from loading, disallowing the user from using it. Instead, you can choose to have the browser go to a different webpage, or simply close the window.

 

14) The finally form should look like the following when an unauthorized user attempts to access the page:

 

Image


0 replies

Be the first to reply!

Reply