Defining a Valid Values Method

When a list of valid values will change frequently, you will usually choose to load it dynamically. To do so, you must write a PBL method which will return the list or choose an existing method or array attribute.

The advantages of a using a PBL method to populate a list of valid values are that you can use data from any source, and that you read this data when it is needed, so it is always current. You can also write a method that generates values with an algorithm and does not obtain data from an external source.

You can load a list of valid values dynamically using:
  • A method that obtains the values from an external source, such as a database or a Web service, or that generates the values in some other way.
  • An array attribute of the same data type as the attribute the valid values are for. For instance, an Int[] array can hold valid values for an Int attribute.

To define a dynamic method valid values list:

  1. In the Valid Values section of the attribute editor, select Dynamic Method. The Method Descriptions option and the Method or attribute used to load valid values panel appear. In the panel, the drop-down list contains currently available methods which return an array of the data type required, as well as array attributes also of the required data type.
  2. If you want the valid values list to contain value-description pairs, click on the Method Descriptions option. If you check this option, an associative array is expected. If not, an indexed array is expected. Therefore, the list of matching methods and attributes will depend on your choice.
  3. You can select an existing method or attribute from the drop-down list. If you need to create a new method, go to step 4. Otherwise, select the method or attribute and save your changes.
  4. To create a new method click New. The Method dialog box appears.
  5. Enter the name of the new method in the Method Name field, and click OK. A PBL method editor opens. In the Properties window, note that Studio set the return type to match that required by the attribute.
  6. If your method will access a database or other catalog component with external dependencies, set Server Side Method to Yes in the Properties window.
    Note: In ALBPM, a server side PBL method executes in the process execution engine. If a method is not server side, it executes where it is called, and may execute in the WorkSpace server. For the purposes of this setting, the WorkSpace considered to be the "client". PBL methods are never executed at the browser.
  7. Enter your method into the editor. Your method must contain a return statement at the end which specifies the variable to be returned. See the examples below.
  8. Save your changes and close the PBL editor and the attribute editor.

Examples

The following PBL method loads a list from SQL table suppliers into the valid values list of an integer attribute. This table was previously introspected into the project catalog as an SQL component. In this table, supplierId is an Int, and supplierName is a String.

In this case the valid values list has descriptions, so an associative array in the form String[Int] must be returned:

listValues as String[Int]

for each record in
    SELECT supplierId, supplierName
    FROM suppliers
do
    listValues[record.supplierId] = record.supplierName
end

return listValues

The following loads the first 11 numbers of the Fibonacci sequence into a valid values list with no description, so it returns an indexed array:

fNumber as Int[]

fNumber[0] = 1
fNumber[1] = 1

for n in 2..10 do
   fNumber[n] = fNumber[n - 1] + fNumber[n - 2]
end

return fNumber