Setting Dynamic Default Values for Filter Controls


When assembling pages from external content, you can personalize default values for filters in a page based on users or conditions. This feature uses an amper-amper (&&) global variable to specify the default option for a filter control. You can then use variables, functions, and conditions to set the values of these global variables. For example, you can set the Region value for a user, using the && global variable, and link it to the filter control to show their region as the selected value, or you can base the default values for a calendar control on the current date so that they always show a relevant, relative date range.

Procedure: How to Personalize Default Values for Filter Controls

You can use global variables to dynamically set the default values of filter controls based on the user who is running the page.

  1. Start by creating a FOCEXEC which specifies the global variable and the default values. In this example, we are setting default values for different users for the Region control.
    1. On the default WebFOCUS start page or Home Page, in the Workspaces area, on the Action bar, click the Other tab, and then click Text Editor.

      The New Text Resource dialog box opens

    2. In the New Text Resource dialog box, click FOCEXEC (fex).

      The WebFOCUS Editor opens.

    3. Add the following FOCEXEC code to set the global variable:
      - &&DEFREGION
      -SET &&DEFREGION= IF &FOCSECUSER EQ 'user1' THEN 'North America' ELSE
      IF &FOCSECUSER EQ 'user2'  THEN 'EMEA' ELSE  'South America'
      
    4. Save your changes and close the Text Editor.
    5. Publish the FOCEXEC.
  2. Bring the global variable in effect by either running the FOCEXEC or mapping its path in the Administration Console for it to be run when the user signs in.

    To map the FOCEXEC you just created in the Administration console, add the focexec path to the Paths to be executed on user Sign-in field in the Other section under Application Settings. The FOCEXEC path name can be copied from the Properties panel in the start page or Home page.

    Note: If you are setting the focexec to be executed on sign in, make sure that the WebFOCUS user credentials are passed to the server. One way to do that is to set the server connection to Trusted and select the Pass WebFOCUS User ID and other Groups radio button. For more information on how to use Administration Console, see the WebFOCUS Security and Administration technical content.

  3. Assemble a visualization from existing content, as described in Creating a Visualization With Existing Content in WebFOCUS Designer.
  4. Populate your new page with the content that features the Region parameter and add the Region filter to the canvas from the Filters tab on the sidebar, as described in Applying Prompted Filters From External Content.
  5. Click the Region filter, open the Properties panel and, in the Settings tab, under Data Settings, type the default value variable that you created in the FOCEXEC (in this case, &&DEFREGION).

    The following image shows an example of the Default value property populated with the variable.

  6. Save, publish, and run your page.

    The default value for the Region filter control is North America, as shown in the following image.

  7. Sign in to WebFOCUS as one of the users mentioned in the FOCEXEC.
  8. Run the same page.

    The following image shows an example of the user with the username user1 running the page. The default Region value now is EMEA.

Procedure: How to Set a Dynamic Default Range for a Calendar Control

A calendar control in a page assembled from existing content is a combined control that allows you to filter for a date range by selecting a start date and an end date. You can use date functions to set global variables for the start and end date to a fixed length of time from the current date, then use those global variables as the default start and end date values for a calendar control.

The calendar control default dates must be entered using the full month name, for example, December 31 2019.

  1. Start by creating a FOCEXEC procedure that specifies global variables for the default start and end dates. In this example, we will make the default start date a week before today, and the end date today.
    1. On the WebFOCUS start page or Home Page, in the Workspaces area, on the Action bar, click the Other tab, and then click Text Editor.

      The New Text Resource dialog box opens.

    2. In the New Text Resource dialog box, click FOCEXEC (fex).

      The WebFOCUS Editor opens.

    3. Add the following FOCEXEC code to set the global variable:
      -SET &LASTWEEK = AYMD(&YYMD, -7, 'YYMD');
      -SET &&FROM_DATE = CHGDAT('YYMD', 'MDYYX', &LASTWEEK, 'A17');
      -SET &&TO_DATE = CHGDAT('YYMD', 'MDYYX', &YYMD, 'A17');
      -DONE

      Three variables are defined in this FOCEXEC: &LASTWEEK, &&FROM_DATE, and &&TO_DATE. &LASTWEEK is a variable that provides the date from one week ago. It does need to be used directly in the calendar control, so it is not created as a global variable. &&FROM_DATE and &&TO_DATE need to be saved for use as default values in the calendar control in our page, so they are created as global variables.

      &LASTWEEK is created using the AYMD function, which takes a date, a number of days to add to that date, and a date format. In this case, we are using &YYMD, which is a system variable that provides the current date in YYMD (year-month-day) format. We are subtracting one week (seven days) from the current date. The date format is YYMD.

      The date format needs to use the full month name, and must be in month-day-year order. We will use the CHGDAT function to convert the date to the proper format for both the &&FROM_DATE and the &&TO_DATE global variables. The CHGDAT function uses four parameters: the format of the input date, the order of the output date, the input date value, and the output date string format as an alphanumeric field.

      The format of our two input dates, the date of one week ago set by the AYMD function and the current date, are both in YYMD format, so that is the first argument of both CHGDAT functions. Similarly, the output of both functions is MDYYX, which generates a date with the full month name in month-day-year order. Typically, the format for such a date would be MtrDYY, but since the CHGDAT function uses date character strings instead of actual date values, it has its own date format designations. MDYY sets the date order as month-day-year, with the year written in four digits, and the X indicates that the full month name should be displayed.

      The third argument of the CHGDAT function is the date to be converted. For the &&FROM_DATE variable, it is &LASTWEEK, which was previously defined in this FOCEXEC using the AYMD function. For the &&TO_DATE variable, it is &YYMD, a system variable representing the current date in YYMD format.

      Finally, A17 defines the string length of the converted date. 17 characters is long enough to fit any date string.

      For more information about the AYMD and CHGDAT functions, see the Using Functions technical content.

    4. Save your changes and close the Text Editor.

      The FOCEXEC must be available to any users for whom you want to set default values in the page. Save it in a location where it will be accessible and then publish the FOCEXEC, or share it with any users after saving.

  2. Bring the global variable into effect by either running the FOCEXEC or mapping its path in the Administration Console for it to be run when the user signs in.

    To map the FOCEXEC you just created in the Administration console, add the focexec path to the Paths to be executed on user Sign-in field in the Other section under Application Settings. The FOCEXEC path name can be copied from the Properties panel on the start page or Home page.

  3. Assemble a visualization from existing content, as described in Creating a Visualization With Existing Content in WebFOCUS Designer.
  4. Populate your new page with the content that is filtered for a date range, and add the calendar control to the page using the Quick Filter button, as described in Applying Prompted Filters From External Content.
  5. Select the calendar control, open the Properties panel and, in the Settings tab, under Data Settings, type the default value variables that you created in the FOCEXEC (in this case, &&FROM_DATE for the first value and &&TO_DATE for the second value).

    The following image shows an example of the Default value property populated with the variable.

    Global variables set as defaults for calendar control

  6. Save and run your page.

    The default date range in the calendar control is automatically set to the past week. The dates will update every day to always represent a period of one week.

    Page with calendar control defaulting to the past week