A110 – Create a specific action
What you will learn ?
How to add a specific action on a business object


STEP 1: Create a calculated field
Prerequisites:
- A customer score
cliScore
read-only field should be added to theAppClient
object. - This field will be filled with specific code of an action of the object.
Exercise:
- Open
AppClient
object. - Click on Add a field and follow the steps of the wizard

STEP 4: Create an action

- Open the Administration menu
- Click on Action to display the search action form
- Search the action or create a new one
Exercise:
- click on Create to define a new action.

STEP 5: Configure the action
Enter:
- Name: for example prefix with the name of the object and a qualifier for the action
- Type: it is the display type, it can be Hidden or Enable on list (action on all records of the current search) and / or in the object form.
- Asynchronous: Synchronous (blocking the user) or Asynchronous (to give the hand to the user if the action is long)
- Async jobs depth : Indicate the depth of log traces. if the number is positive it is in quantity, if the number is negative it is in rolling days.
- Method: a method name coded in each object that will use the action
- Processing expression: a JavaScript expression (the script will be interpreted on the fly during the use of the action)
- URL: Path to a redirect page (ex. SYS_work.jsp, ALL_form.jsp or any http), or to a specific page (JSP or servlet) coding in the project or JavaScript code (in this case prefix the URL with JavaScript:)
- Enter an Image URL to represent the action, if none the action will be displayed as a button
- Indicate whether the action must be confirmed by the user
- If it is displayed in the Plus menu
- Select the module
Exercise:
Create the action that will calculate the customer score by script:
- Name = AppClient-Score
- Enable on form only
- Synchronous
- Without confirmation from the user
- With the following JavaScript in Processing expression:
var clientId = obj.getRowId(); var score=0; var o = obj.getGrant().getTmpObject("AppClientInteret"); o.resetFilters(); o.setFieldFilter("cintClientFK",clientId); var rows = o.search(); for (var i = 0; i < rows.size(); i++) { o.setValues(rows.get(i)); score = score+o.getField("cintInteretFK.intScore").getInt(0); } obj.getField("cliScore").setInt(score); obj.save();
Explanation of the script line by line:
- Found the customer row_id on which the action is called
- Defines a SQL query that calculate the sum of the customer score
- Run the query
- Set the cliScore value
- Save the customer

STEP 7: Create a function

To enable an action, you must first define a function that will make the relation between the object and the action:
- Go to the Function tab
- Click on
Create

STEP 8

Fill in the form of the function:
- Give a name to the function: by convention we use the same name as the action
- Select the object that will carry the action (so we can create several functions using the same action for different objects)
- Select the function type = Action
- Select the module Save.
Exercise:
Create a function on the action AppClient-Score-A

STEP 9: Grant the function

Finally, like any function, grant it to rights groups
Exercise:
- Grant the function to
MyAdminGroup

STEP 11: Test the action

Open the object containing the action and check that it performs well what is set.
Exercise:
- Open a customer who has interests
- Check that the total calculation works by clicking on the button
Calculate score
If action is not visible is that the user is not in a group granted to the function of the action.
If the calculation does not work, look out for the logs and fix the code.
Remember to clear the cache at each update.
A100 – Create a field type
Create an external field type.