CodeCharge Studio

Programmatically Control Field's Value

Once you add Custom Code to the Event, you will see the code-editing window with the appropriate place to enter the new code.

  1. Replace the following line of code:
    /* Write your own code here. */

    with the following:

    String user_id_assign_to = e.getGrid().getControl("user_id_assign_to").getFormattedValue();
    String login = Utils.getUserLogin(e.getPage());
    if ( user_id_assign_to != null && user_id_assign_to.equals(login))
    {
      String task_name = e.getGrid().getControl("task_name").getFormattedValue();
      task_name = "<b><font color=\"blue\">"+ task_name + "</font></b>";
      e.getGrid().getControl("task_name").setFormattedValue(task_name);
    }

Let's explain how the above JSP code works:

String user_id_assign_to = e.getGrid().getControl("user_id_assign_to").getFormattedValue();
String login = Utils.getUserLogin(e.getPage());
if ( user_id_assign_to != null && user_id_assign_to.equals(login)) {

The above lines prepare and then execute the "if" condition that checks if the value of the current control (user_id_assign_to) is equal to the user login name. Once you login to the system, the program will recognize your tasks by comparing your login name to the emp_login value of the person that a task is assigned to. Utils.getUserLogin(Page) method is one of the static auxiliary methods in Utils class, and it holds the Login name of the currently logged in user until the session expires.

Note:

The following are different helpful functions from the Utils class:

Page parameter is needed to get access to Session object, where these values are stored actually.

e.getGrid().getControl("task_name").setFormattedValue(task_name);

This code is executed if the previous "if" condition is met. It modifies the value of the current control (user_id_assign_to). The field value is replaced with the user login name value wrapped within HTML code that specifies the font color as blue, and adds HTML <b> tag to make the font bold as well. Notice that the word blue has escaped quotes around it, which will be replaced with a single quote at runtime. Since quotes mark the start and end of a string, using escaped quote allows you to insert a quote into a string.

Next: Preview the Tasks List Page


On-line, printable versions and updates