W050 – Routing

What you will learn ?

How to create different end to an activity in a business process

STEP 1: Prerequisites

You must first create all the transitions from one activity to all possible destinations.

Exercise:

Add an activity CreateAddress in the AppCreateCustomer process using the wizard:

  • Code = APPCC-ADDRESS
  • Name = CreateAddress
  • Type = New
  • Irreversible
  • User dialog = Yes
  • Module = MyModule
    then:
  • Translate by Create a main address with enter an address for the customer
  • Give the write permission to MyAdminGroup group
  • From CustomerEntry and to Interest
  • Data: Object Name = AppAdresse

Place the activity on the process diagram and save.

STEP 2: Set condition

On each transition, a condition must be set by a code that will return the business (given Return.Code) to go to that direction.

Exercise:

  • Double-click on the transition going to the creation of the address
  • In the transitional form, write EmptyAddress in the Condition field
  • Save
  • The condition (EmptyAddress) appears on the diagram above the link between the two activities

STEP 3: Default path

It may be useful to indicate a default transition that will be followed if no alternate path meets condition (Data Return.Code).
The condition must be the special code [DEFAULT].

Exercise:

  • Set [DEFAULT] in the condition between CustomeEntry and Interest

STEP 4: Return code activity

Then you will have to set the value of the Return.Code activity data There are several ways to set this value :

  • By script or code on the postValidate hook which is called after the validation of an activity and before choosing the path to continue
  • By setting the Return.code of a given activity (Group = Return, data = Code), the value is in this case a data activity or data process (ex. for an activity related to a business object: [<step>.Field.<field name>])

Exercise:

At the exit of CustomerEntry, we want to test if the customer has an address. If not we redirect to the activity of creating a new address. By code:

  • Edit Script process
  • Add the following code:
    AppCreateCustomer.postValidate = function(context) {
    console.log("BEGIN postValidate");
    var step = context.getActivity().getStep();
    if (step=="APPCC-CLIENT") {
        var adresseId = context.getDataFile("Field", "cliAdresseFK", true).getValue(0);
        console.log("adresseId=["+adresseId+"]");
    
        if (!adresseId || adresseId.equals("")) {
            console.log("empty address ");
            context.setDataFile("Return", "Code", "EmptyAddress");
        }
    }
    console.log("END postValidate");
    };

    Code Explanation:

  • The postValidate hook takes the context of the current activity of the process and the step of the process.
  • If the step is creating the customer, we get the reference value of the address
  • If this reference is not set, it forces the return code to EmptyAddress which is the condition that goes to the CreateAddress activity
    (If nothing is specified the next activity is Interest because the condition is set to [DEFAULT])

Option:

  • At the definition of AppClient object, create a hidden calculated field cliMainAddress which would be equal to EmtyAddress if the address is missing
  • And the definition of CustomerEntryactivity, add the data Return.Code = [APPCC-CLIENT.Field.cliMainAddress]

STEP 5: postValidate hook

The postValidate hook of a process can act:

  • After validation of the activity: the activity is complete and saved
  • Before choosing a path for the future activity: very useful to give a value to a Return.Code corresponding to a condition transition
  • To add a specific treatment on the activity before going to the next activity

Exercise:

After the CreateAddress activity, associate the new address to the previously created customer.

  • Edit AppCreateCustomer process script
  • Update the code of the postValidate hook with the following:
    AppCreateCustomer.postValidate = function(context) {
    console.log("BEGIN postValidate");
    var step = context.getActivity().getStep();
    if (step=="APPCC-CLIENT") {
        var adresseId = context.getDataFile("Field", "cliAdresseFK", true).getValue(0);
        console.log("adresseId=["+adresseId+"]");
    
        if (!adresseId || adresseId.equals("")) {
            console.log("empty address ");
            context.setDataFile("Return", "Code", "EmptyAddress");
        }
    }else if (step=="APPCC-ADDRESS") {
        var a = this.getActivity("APPCC-CLIENT");
        var af = this.getContext(a);
        var clientId = af.getDataFile("Field", "row_id", false).getValue(0);
        var c = this.getGrant().getTmpObject("AppClient");
        c.resetFilters();
        if (c.select(clientId)) {
            var adresseId = context.getDataFile("Field", "row_id", true).getValue(0);
            console.log("update clientId="+clientId+" adresseId="+adresseId);
            c.getField("cliAdresseFK").setValue(adresseId);
            c.save();
        }
    }
    console.log("END postValidate");
    };

    Code Explanation:

When the step is the address creation:

  • Find the reference field of the customer created in the APPCC-CLIENT activity
  • Select a temporary instance of the object AppClient
  • Change the reference field address to the one that has just been created
  • Save the customer to update its address

STEP 6: test and validate

Do some tests for each possible condition, to validate that the next activity is the one expected.

Exercise:

  • Clear all caches
  • Launch process by creating a customer with / without address

W040 – Redirection to specific page

Redirect to a specific page at the end of the business process

W060 – Create an alert

How to set an alert.