UI actions

Let us now create a server-side UI action. A UI action can be invoked from different UI elements, such as form buttons, form list context menus, form-related links, list of records header context menus, list actions menus, or list-related links. UI actions are usually server-side code, and can make use of script includes and other server-side client APIs. However, it is also possible to mark a UI action to run on client- and write- and use-only client-side glide APIs.

For the purpose of this book, we will create server-side UI actions. Our goal is to provide a button on the top of the form, in the form header and context menu, to allow users to set the state of a pending or open booking request as a work in progress.

To create a new UI action, open Studio, select Server Development | UI Action from the Create Application File wizard, and click Create:

Fill in the UI action New Record form with the following values:

  • Name: In Progress
  • Table: Booking Request
  • Action name: mark_in_progress
  • Show insert: Unchecked
  • Show update: Checked
  • Client: Unchecked
  • Form button: Checked
  • Form context menu: Checked
  • Condition: javascript:(current.state==-5 || current.state==1)
  • Script: (As detailed here)
  • Protection policy: Read-only

The script for the UI action is very simple and is comprised of just two lines of code:

current.state=2; //2 refers to work in progress 
current.update(); //unlike before business rules explicit call to save the form is required in UI actions 

The Form button and Form context menu will appear when the condition we have defined in the UI action evaluates to true. The script will execute when we click on the Form button or the Form context menu we have defined using the UI action. All we are trying to do in the script is to mark the state field as a work in progress.

Let us test our UI action by switching to the main service now interface and opening an existing record in the Booking Request table. Open the Travel Booking Application | Booking Request list of records module and click on one of the existing records to open it in edit form. If the record is either in a pending or open state, then the condition defined in the UI action will match and we will be able to see a button and context menu entry in the form header.

The In Progress form button UI action will appear on the form header, as shown here:

The In Progress form context menu UI action is shown here:

Similarly, we can create a form-related link and actions for the list of records modules by checking the different options available in the UI action form.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.244.153