How to create own application menu method?

The sample program was prepared for this purpose. In the QSAMPLES source file devlivered together with aperio You can find all sources ready to use as dynamic menu structure. The programs and files are ready to compile. You can copy it and adjust or change if needed.

Following sources contain necessary elements to build dynamic menu structure:

MENU_ATTR   PF          Menu items attributes                                                       
MENU_AUTH   PF          Menu items authority                                                        
MENU_GET    SQLRPGLE    applicationMenu.get                                                         
MENU_STR    PF          Menu structure                                                              

The menu structure is stored in MENU_STR. This file contains 3 columns:

  • PARENTID id of parent menu item
  • SEQ sequence
  • CHILDID id of child menu items

Example of menu structure:

  PARENTID       SEQ   CHILDID                                                                      
  A               10   A1                                                                           
  A               20   A2                                                                           
  A               30   A3                                                                           
  A               40   A4                                                                           
  A               50   A5                                                                           
  A               60   A6                                                                           
  A3              10   A31                                                                          
  A3              20   A32                                                                          
  A3              30   A33                                                                          
  A32             10   A321                                                                         
  A32             20   A322                                                                         
  A4              10   A41                                                                          

Next file MENU_ATTR contains attributes for each menu item. Following attributes are mandatory for mobile applications:

  • ’title’ it contains title of menu item
  • ‘form’ It contains form name which will be invoked when user click on menu item.

There is possibility to add more attributes:

  • ‘icon’ It defines the menu item icon
  • ‘method’ It defines method which will be run automatically for visual flows menu type and many more…

Example of MENU_ATTR file data:

  ID          ATTR_ID                         ATTR_VAL                                              
  A1          title                           Menu point A1                                         
  A1          form                            formA1                                                
  A1          icon                            fa-pencil-square-o                                    
  A2          title                           Menu point A2                                         
  A2          form                            formA2                                                
  A3          title                           Menu point A3                                         
  A3          form                            formA3                                                
  A31         title                           Menu point A31                                        
  A31         form                            formA31                                               

Third file MENU_AUTH contains authority information. Each menu item must be defined here at least once. This file describes who has access to menu item. In the field USER it is possible to define iSeries profile or group profile connected to iSeries profile.

Example of MENU_AUTH data:

   ID          USER                                                                                 
   A           IBS11OWN                                                                             
   A1          IBS11OWN                                                                             
   A2          IBS11OWN                                                                             
   A3          IBS11OWN                                                                             
   A4          IBS11OWN                                                                             
   A5          ADMIN                                                                                
   A6          ADMIN                                                                                
   A32         IBS11OWN                                                                             
   A41         IBS11OWN                                                                             
   A42         IBS11OWN                                                                             
   A33         IBS11OWN                                                                             
   A           SALESMAN                                                                             
   A1          SALESMAN                                                                             
   A4          SALESMAN                                                                             
   A41         SALESMAN                                                                             
   A42         SALESMAN                                                                             

In the example above all users which have group profile IBS11OWN, have access to all menu items except A5 and A6. Only user ADMIN is authorised to menu items A5, A6. If user SALESMAN has no group profile IBS11OWN then he has access only to menu items: A, A1, A4, A41, A42

The MENU_GET program builds menu structure based on these 3 files. It retrieves iSeries profile information. The security is based on user profile, group profile and all supplemental group profiles. If there is need to implement any other security rule (e.g. based on different files) the recommendation is to do it in lcl_checkAuhority procedure (at the end of program). This procedure returns *ON, if user has authority to menu item, or returns *OFF, in case user has no authority to menu item. This program can be copied under any other name and compiled.
When program is ready, add to metadata following entry. This will expose program under name applicationMenu.get

API method.......... applicationMenu.get                                                            
Program............. MENU_GET                                                                       

Then in application definition json file, the top menu item of menu structure must be defined.

Example of application definition

{                                                                                                   
 "title": "My Mobile App",                                                                          
 "subtitle": "DC1",                                                                                 
 "link": "/myApp",                                                                                  
 "modules": [                                                                                       
  "myApp"                                                                                           
 ],                                                                                                 
 "menu":"A"
 "browserReload": false,                                                                            
 "development":{                                                                                    
  "tracing": true                                                                                   
 },                                                                                                 
 "version": "1.0.0.0"                                                                               
)                                                                                                   
...
"menu":"A"    <--- Here You define the top element of menu structure    
...