Auto-hide grid columns based on user ID

When creating grid apps, it can be tempting to pull in every conceivable column someone in the company might want to see. Consider, for example, the case of a grid of inventory items. You know users in accounting like to see dollars, while warehouse users like to see quantities, people in purchasing like to see dates, etc… Everybody has something special they want to see.

Listen

While you can certainly leave it to the users to arrange, hide or show columns in the grid apps you create, effective with the latest Valence 6 build (6.0.20201222.0) you can now programmatically turn off columns before users ever see them. So, for example, if you know financial info does not matter to warehouse personnel, you could configure your grid app to permanently omit any value-related columns before it loads. Conversely, you could take columns that are normally hidden by default and set them to “unhide” when the app is launched by select users.

The key to this process is to create App Variables in your grid app to control columns you want to hide, then specify a simple RPG startup program to initialize the App Variables as desired. To illustrate by example, let’s take the customer list app created in last month’s tip and make the “YTD Sales” and “Last Activity” columns hidden for a select user.

We’ll begin by launching Nitro App Builder, then switch to the Apps tab, select the DEMOCMAST Edit Grid app and click on the App Variables button in the upper left…

Listen

The next step is to click the Add button in the upper right and create a new App Variable to control the hide feature on our miscellaneous columns. We’ll call “hideMiscColumns”…

Listen

Now click the Back arrow in the upper left, hover over the grid and click the cogwheel that appears in the upper left, then click on the “Link to App Variables” button…

Listen

Here is where we indicate which columns should be controlled by the App Variable we just created. So scroll down to the Hide Columns section, find the columns to be hidden and select the “hideMiscColumns” App Variable…

Listen

Finally, let’s tell the app the name of a simple RPG program to call that will set the App Variable as needed when the app is launched. Back at the App page, click on the Security Settings icon…

Listen

We’ll call our program NABSTARTUP, placing it in the space to the right…

Listen

Now we’re done with the front end, so save the app and we can turn our focus to the back-end RPG program. In your source editor, copy the NABSTARTUP program, giving it the name you specified in the app (in our case, NABSTARTUP).  Open the source and scroll down to the Process procedure.  Here is where you can add your code to set the hideMiscColumns variable when the app starts up…

Listen

In this crude example we’re using one of the globally available RPG variables, gUser, to see if user JOHNSON is logged in. Of course, you would likely have a more elegant way to determine the department to which the user belongs — i.e., a master table of users — and then set the App Variable accordingly.  

Once compiled, any users identified in the startup RPG program will cause the App Variable to be set to ‘false’ and they will not see the corresponding columns in the grid. It’s just one small way to reduce the data clutter in your grid apps for select users!