Reg Exp
Web Design
Notes Client
Combining Many Views Into One
Recently, we were working on a project where one requirement was to have, according to the specifications, "one view per department showing...". It turns out that the design of the views were going to be identical, they just wanted to see only one department at a time.

Normally, the developer would say "OK" and go down the path of designing the view and then copying and pasting the design element a bunch of times, changing the selection formula slightly, and delivering the finished product. But, with all of our experience, we knew this wouldn't be the best solution. Every time a department was added or two departments were merged into one or the name of a department changed, it would mean a change to one or more design elements. And, although this would be good for job security, it wouldn't be fun having to go in and make trivial changes. Plus, if the underlying design of the view changed, that change would have to be made to all the different design elements.

We came up with a better way. First, we created one view. It was called "Department View". The first column was categorized on the department name, and the rest of the view was designed according to the specifications. Next, we created a page design element called "Show Department View". All the page contained was an embedded view element. We embedded the "Department View" view, and set it up to take up 100% of the available page width and height. The embedded view has a "Show Single Category" value that is optional. We set it to:
This means that the category defined in that environment variable would be the only category to show when the page was opened.

To be able to switch departments, we added an action button to the page called "View Another Department". The action button formula would prompt the user for another department and then reload the page with the new setting:
ENVIRONMENT Department := @Environment("Department");
Options := @Trim(@DbColumn(""; ""; "Department View"; 1));
NewDept := @If(@IsError(Options); @Return(@Prompt([OK]; "Error"; "There was an error. Please contact the application support area.")); @Elements(Options) = 0; @Return(@Prompt([OK]; "Error"; "There was an error. Please contact the application support area.")); @Prompt([OKCANCELLIST]; "Choose Department"; "Please choose the department to view from the list below."; @Environment("Department"); Options));
Check := @If(NewDept = ""; @Return(0); 0);
Save := @SetEnvironment("Department"; NewDept);
@Command([OpenPage]; "Show Department View")

First, the first column of the view is read to get all the department names. If this results in an error or no names, the user is prompted with an error message and the function quits. The user is prompted with the department names, using the current setting as a default, and chooses one. If they click cancel, the function quits. Then the new department name is saved in the environment variable, and the page is reopened in the right frame (we were using a frameset with navigation in the left frame).

To open the page to begin with, the navigation left frame would check to see if the environment variable had been set. If so, the page was opened (so the last viewed department would be seen). If the environment variable had not been set, they would be prompted to choose the department name, the environment variable would be set, and the page opened. So the action to open the page from the navigation is very similar to the action to switch - the only exception would be to only do the prompt for the new department if the current environment variable was blank.

With this method, we were able to satisfy the user requirement of a "different view for each department", while keeping the design down to one view design element and not having to do anything to the design if departments changed. Also, when the look of the view changed (which it did about 3 weeks after going "live"), we only had one design element to update instead of many.

Another alternative to implementing this method would be to remove the action button on the page and do something in the left frame to show all the departments. It would not be as easy to implement as this method, but it could be possible. The easiest way to do it would be to have an outline that lists all the department names and does a formula of setting the environment variable and opening the page in the right frame. However, going this route would also mean having to update the outline design element every time departments are added, removed, or renamed.