Skip to main content

previousAction()

Last updated 22/01/2025

The

function returns to the previously selected or replaced action. It will return selected actions by default, however, by setting the

revertSelect
parameter to
false
you can return replaced actions as well. Optionally, you can pass in a number of actions you want to go back, in the case of more than one action being selected or replaced.

In the previous chapter,

, two processes were created, we are going to build on from that and add another process called Process C to demonstrate the

previousAction()
function. Two buttons will be added to Process C. One button will return to the previously selected action, while the second button will return back the number of actions passed into the
previousAction()
function.


info
The Action Navigation application is created to demonstrate the
previousAction()
function, the creation of this application is documented in the Introduction chapter so you can perform the tutorial. The
previousAction()
tutorial follows on from the
selectAction()
tutorial.




Multiple actions and functions are used to demonstrate returning previously selected actions. All the functions will be added first.

In this tutorial, the following will be performed to demonstrate how

selectAction()
and
previousAction()
work together:

  • Add the
    ToProcessA()
    function - When on Process B, will select Process A using
    selectAction()
    .
  • Add the
    ToProcessC()
    function - When on Process B, will select Process C using
    selectAction()
    .
  • Add the
    Previous1()
    function - When on Process C, will return you to Process B using
    previousAction()
    .
  • Add the
    Previous2()
    function - When on Process C, will return you to Process A using
    previousAction()
    and passing in the optional
    number
    parameter.
  • Edit the Process B record - To add the screen fields Back to Process A and To Process C, these fields will have a _Button display type and respectively will have the
    ToProcessA()
    and
    ToProcessC()
    functions attached.
  • Add the Process C record - With the screen fields Back One Action and Back Two Actions, these fields with have a _Button display type and respectively have the
    Previous1()
    and
    Previous2()
    functions attached.

Add the ToProcessA Function

The

ToProcessA()
function will use Five's
selectAction()
function on the
Five
object and pass in the action ID
ProcessA
. This will select Process A from Process B.

1. Select Logic in the menu.

2. Select Functions in the sub-menu.


Functions menu item
Figure 1 - Functions menu item

3. Click the Add Item button.

4. Type ToProcessA in the Function ID field.

5. Click in the Code field to open the Code Editor.


Add ToProcessA function
Figure 2 - Add ToProcessA function

6. Copy and paste the code block below into the editor.

note
The code block needs to be pasted over the template that Five creates in the editor.

JavaScript
Selects the action ID ProcessA
function ToProcessA(five, context, result) {
five.selectAction('ProcessA');
return five.success(result);
}

7. Click the Save button in the Code Editor app bar.


Save button
Figure 3 - Save button

8. Click the Save button in the form app bar.


Save button
Figure 4 - Save button

Add the ToProcessC Function

The

ToProcessC()
function will use Five's
selectAction()
function on the
Five
object and pass in the action ID
ProcessC
. This will select Process C from Process B.

1. Click the Add Item button.

2. Type ToProcessC in the Caption field.

3. Click in the Code field to open the Code Editor.


Add ToProcessC function
Figure 5 - Add ToProcessC function

4. Copy and paste the code block into the editor.

note
The code block needs to be pasted over the template that Five creates in the editor.

JavaScript
Selects the action ID ProcessC
function ToProcessC(five, context, result) {
five.selectAction('ProcessC');
return five.success(result);
}

5. Click the Save button in the Code Editor app bar.


Save button
Figure 6 - Save button

6. Click the Save button in the form app bar.


Save button
Figure 7 - Save button

Add the Previous1 Function

The

Previous1()
function will use Five's
previousAction()
function on the
Five
object to return to the previously selected action. No parameters need to be passed into the
previousAction()
function when returning to the previously selected action, by default, Five sets
true
and
1
which will take you back to the previously selected action.

1. Click the Add Item button

2. Type Previous1 in the Function ID field.

3. Click in the Code field to open the Code Editor.


Add Previous1 function
Figure 8 - Add Previous1 function

4. Copy and paste the code block below.

note
The code block needs to be pasted over the template that Five creates in the editor.

JavaScript
Returns to the previously selected record
function Previous1(five, context, result) {
five.previousAction();
return five.success(result);
}

5. Click the Save button in the Code Editor app bar.


Save button
Figure 9 - Save button

6. Click the Save button in the form app bar.


Save button
Figure 10 - Save button

Add the Previous2 Function

The

Previous2()
function will use Five's
previousAction()
function on the
Five
object and the optional
number
parameter to return back the number of previously selected actions passed into the function.
true
needs to be passed into the
previousAction()
function as the first parameter and the number of actions you wish to return needs to be supplied as the second parameter.

1. Click the Add Item button.

2. Type Previous2 in the Function ID field.

3. Click in the Code field to open the Code Editor.


Add Previous2 function
Figure 11 - Add Previous2 function

4. Copy and paste the code block below into the editor.

note
The code block needs to be pasted over the template that Five creates in the editor.

JavaScript
Returns back 2 previously selected actions
function Previous2(five, context, result) {
five.previousAction(true, 2);
return five.success(result);
}

5. Click the Save button in the Code Editor app bar.


Save button
Figure 12 - Save button

6. Click the Save button in the form app bar.


Save button
Figure 13 - Save button

Edit Process B

The Process B record that was added in the previous chapter,

, needs to be edited to add the buttons that will navigate you to Process A and Process C. Each button will have an On Click event and when clicked, the functions will execute and select the respective processes.

1. Select Tasks in the menu.

2. Select Processes in the sub-menu.


Processes menu item
Figure 14 - Processes menu item

3. Select the Process B record in the list.

4. Click the Screen Fields tab.


Screen Fields tab
Figure 15 - Screen Fields tab

5. Click the Add Screen Fields button.


Add Screen Fields button
Figure 16 - Add Screen Fields button

6. Type Back to Process A in the Caption field.

7. Click the lookup icon in the Display Type field and select _Button.


Add Back to Process A screen field
Figure 17 - Add Back to Process A screen field

8. Click the Events tab.


Events tab
Figure 18 - Events tab

9. Click the lookup icon in the On Click field and select ToProcessA.


On Click field
Figure 19 - On Click field

10. Click the Save button in the form app bar.


Save button
Figure 20 - Save button

11. Click the Add Screen fields button.


Add Screen Fields button
Figure 21 - Add Screen Fields button

12. Type To Process C in the Caption field.

13. Click the lookup icon in the Display Type field and select _Button.


Add To Process C screen field
Figure 22 - Add To Process C screen field

14. Click the Events tab.


Events tab
Figure 23 - Events tab

15. Click the lookup icon in the On Click field and select ToProcessC.


On Click field
Figure 24 - On Click field

16. Click the Save button in the form app bar.


Save button
Figure 25 - Save button

17. Click the Save button in the form app bar above the list.


Save button
Figure 26 - Save button

Create Process C

Process C needs two screen fields with the display type of _Button. The Back One Action button will have the

Previous1()
function attached to the On Click event. When the button is clicked, the function will execute and return you to the previously selected action. The Back Two Actions button will have the
Previous2()
function attached to the On Click event. When the button is clicked, the function will execute and return back two previously selected actions.

1. Click the Add Item button.

2. Type Process C in the Title field.

Add Process C
Figure 27 - Add Process C

3. Click the Screen Fields tab.


Screen Fields tab
Figure 28 - Screen Fields tab

4. Click the Add Screen fields button.


Add Screen Fields button
Figure 29 - Add Screen Fields button

5. Type This is Process C in the Caption field.

6. Click the lookup icon in the Display Type field and select _Label.


Add This is Process C screen field
Figure 30 - Add This is Process C screen field

7. Click the Save button in the form app bar.


Save button
Figure 31 - Save button

8. Click the Add Screen Fields button.


Add Screen Fields button
Figure 32 - Add Screen Fields button

9. Type Back One Action in the Caption field.

10. Click the lookup icon in the Display Type field and select _Button.


Add Back One Action screen field
Figure 33 - Add Back One Action screen field

11. Click the events tab.


Events tab
Figure 34 - Events tab

12. Click the lookup icon in the On Click field and select Previous1.


On Click field
Figure 35 - On Click field

13. Click the Save button in the form app bar.


Save button
Figure 36 - Save button

14. Click the Add Screen Fields button.


Add Screen Fields button
Figure 37 - Add Screen Fields button

15. Type Back Two Actions in the Caption field.

16. Click the lookup icon in the Display Type field and select _Button.


Add Back Two Actions screen field
Figure 38 - Add Back Two Actions screen field

17. Click the Events tab.


Events tab
Figure 39 - Events tab

18. Click the lookup icon in the On Click field and select Previous2.


On Click field
Figure 40 - On Click field

19. Click the Save button in the form app bar.


Save button
Figure 41 - Save button

20. Click the Save button in the form app bar above the list.


Save button
Figure 42 - Save button

How This Works in an Application

Deploy/run your application, you will be positioned on Process A. Click the To Process B button.


To Process B button
Figure 43 - To Process B button

The event will execute the

ToProcessB()
function and selects Process B. This is because
ProcessB
is passed into
selectAction()
. Click the Back to Process A button.


Back to Process A button
Figure 44 - Back to Process A button

The event will execute the

ToProcessA()
function and selects Process A. This is because
ProcessA
is passed into
selectAction()
. Click the To Process B button again.


To Process B button
Figure 45 - To Process B button

You are returned to Process B. Click the To Process C button.


To Process C button
Figure 46 - To Process C button

The event will execute the

ToProcessC()
function and selects Process C. This is because
ProcessC
is passed into
selectAction()
. Click the Back One Action button.


Back One Action button
Figure 47 - Back One Action button

The event will execute the

Previous1()
function and returns you to the previously selected action, which is Process B. This is because no parameters were passed into
previousAction()
, so the default parameters,
true
and
1
are used. Click the To Process C button again.


To Process C button
Figure 48 - To Process C button

You are returned to Process C. Click the Back Two Actions button.


Back Two Actions button
Figure 49 - Back Two Actions button

The event will execute the

Previous2()
function and returns you back two previously selected actions, which is Process A. This is because we passed in
true
and
2
into
previousAction()
using the optional
number
parameter. This all happens without leaving the Process A menu item.


Process A
Figure 50 - Process A