Wednesday, December 3, 2014

How to change the Enter key functionality

In Sage X3 screens, the Enter key usually has some default functionality - for example, it might be triggering the OK button. Regardless of what the actual default functionality is, here is how you can block it or replace it with something else.

When the Enter key is pressed, X3 assigns the value GSTARET to the variable REPONSE. You can check for that condition in the 'After Choice' action. Depending on the template you are using, this action might be APRES_CHOI or AP_CHOIX. For the examples below, we will use APRES_CHOI.

First of all, you need to add the action to the list of actions in the $ACTION label of your specific processing file like this:

$ACTION
Case ACTION
# ... Other actions ...
  When "APRES_CHOI" : Gosub APRES_CHOI
# ... Other actions ...
  When Default
Endcase
Return


Then, in the action handler, if you just want to stop the standard Enter key functionality from executing, you can do:

$APRES_CHOI
If REPONSE=GSTARET : REPONSE=0 : Endif
Return


And if you want to replace it with new functionality:

$APRES_CHOI
If REPONSE=GSTARET
    REPONSE=0
    Infbox("Custom functionality goes here!")
Endif
Return


Once you make sure that the Infbox statement is getting executed when you press Enter in your screen, you can put in its place something actually useful, depending on your needs.