Skip to main content

Function Library

Overview

A Function Library is a Class, the Functions it contains are Public Static Methods of the class, which must not be Overloaded and must derive from the Enactor base class.

The Functions in the Library may receive arguments and return values of any declared type and may be part of a larger EL expression or supplied as an argument to another function. However, where properties supply arguments or receive return values, they must meet the requirements for Expression Language Data Binding as discussed in section Expression Language Data Binding in Enactor.

In this tutorial, we will be displaying the User details using some Enactor Function Library methods.

What you will learn

How to use below enactor Function Library methods.

  • substring()
  • trim()
  • indexOf()

Pre-requisite

Should have followed Application Process Tutorial

Adding an Assign Action

Open the DisplayLoggedinUser process which you created from Application Process Tutorial

From the Palette, expand the Actions Group, Drag and drop a new Assign action near ShouldPromptForLoggedinUser message state.

Move the link from StateEntered outcome of Start state to the new Assign Action.

From the Palette, click the Link tool and then add a link from the Success outcome on the new assign action connecting it to the ShouldPromptForLoggedinUser state.

Right click the new Assign action and select Show Properties

Set the Action ID to SetUserDetails

In order to add the User input to the new Assign action, drag the User input from the ShouldPromptForLoggedinUser state to the input section of the Assign action.

We need to initialize new variables to pass the User forename and surname. For that add the following outputs to the Assign action.

NameType
enactor.coreUI.UserForenamejava.lang.String
enactor.coreUI.UserSurnamejava.lang.String

Using String Function Library

Double click on the Assign Action. Then double Click on the from Expression. It will open up Configure Expression Dialog.

Expand Functions to view all Available Function Libraries.

Under that, expand String Functions and double click on strings:substring(string, integer, integer) so that it appears on the expression tab.

Now, we need to replace the value for string and integer values.

Select string part inside brackets and navigate to Properties -> User. Double click on the displayName so that the string is getting replaced with the user.displayName.

Then, replace the first integer value with 0.

Replace the second integer by navigating to String Functions->strings:indexOf(string, string)

Now the string values of indexOf function need to replaced.

Replace the first string with the user.displayName as done previously.

Then replace the first string with " ".

The final from expression should be as follows.

strings:substring(user.displayName, 0, strings:indexOf(user.displayName, " "))

Click OK.

Now, double click on the To Expression and select userForename.

In the same way add the below expression as well.

From expressionTo Expression
strings:trimString(strings:substring(user.displayName, strings:indexOf(user.displayName, " "), length(user.displayName)))userLastName

Finally, your expressions should display as below.

info

You can view the existing Funtion Libraries under Functions on the Data Assignments Popup.

The ShouldPromptForLoggedinUser Message State should now be modified by adding the above given outputs as inputs. You can drag and drop the given two outputs to the Input section of the Message State.

Right click on the Message state and select Show Properties

Modify the Message Text with the below given Text.

Your User Details <br/> ForeName : ''{userForename}'' <br/> LastName: ''{userSurname}''

Your final process should display as below.

Save the changes.

Re-Launch the Pos application. After you sign in, a dialog should now be presented with the below message.

Further Reading

We can also use Function Library with Beanshell Scripts. Refer Beanshell Scripts for more information.