CodeCharge Studio

Use the Before Show Event to Alter a Label's Value

  1. Select the Label user_id_assign_by in the Project Explorer.
  2. Click on Data tab in Properties window.
  3. Select Text as the Data Type.
  4. In the Properties window click on the Events tab.
  5. Right-click on Before Show event and select Add Code.... .

    CodeCharge Studio should then automatically switch to Code view.

    CodeCharge Studio should then automatically switch to Code view.

  6. Once in Code view, you should see the following lines of code:
    //user_id_assign_by Label Handler Head @13-91DFA71C-->
    public class tasksuser_id_assign_byLabelHandler implements LabelListener
    {
      public void beforeShow(CCSEvent e)
      {
        //End user_id_assign_by Label Handler Head-->
    	
        //Event BeforeShow Action Custom Code @13-4EFC2132-->
        /* Write your own code here. */
        //End Event BeforeShow Action Custom Code-->
    	
        //user_id_assign_by Label Handler Tail @13-F5FC18C5-->   
      }
    }
    //End user_id_assign_by Label Handler Tail-->

    Replace the text:

    /* Write your own code here. */

    with the following:

    if (e.getRecord().isEditMode()) 
    {
      e.getControl().setValue(DBTools.dLookUp("emp_name", "employees", "emp_id=" + 
      DBTools.toSql(e.getControl().getFormattedValue(),JDBCConnection.INTEGER,"IntranetDB"), "IntranetDB"));
    } 
    else 
    {
      e.getControl().setValue(DBTools.dLookUp("emp_name","employees", "emp_id="+ 
      DBTools.toSql(Utils.getUserId(e.getPage()),JDBCConnection.INTEGER,"IntranetDB") , "IntranetDB"));
    }

    In the above code, the first "if" block checks if the current record form is in the update mode and if so, it retrieves the name of of the appropriate employee and assigns it to the current control's value. If the form is not in the update mode, the name of the currently logged in user is assigned as the control's value.

    The following elements make up the code:


    The whole code snippet reads approximately as follows:


Next: Add a Hidden "Assigned By" Field to Auto-Update New Tasks


On-line, printable versions and updates