Once in Code view, replace the following text:
'Write your own code here.
with the following:
If tasks.EditMode Then
tasks.user_id_assign_by.Value = CCDLookUp("emp_name", "employees", "emp_id=" &_
DBIntranetDB.ToSQL(tasks.user_id_assign_by.Value, ccsInteger), DBIntranetDB)
Else
tasks.user_id_assign_by.Value = CCDLookUp("emp_name", "employees", "emp_id=" &_
DBIntranetDB.ToSQL(CCGetUserID(), ccsInteger), DBIntranetDB)
End if
The above code consists of the following elements:
- tasks -the name of the record form on the page
- EditMode - property of the form, which specifies if the record is being edited. Depending on the value of this property, we either display the name of the person who originally submitted the task (Edit mode), or the person who is currently submitting the task (Insert mode).
- user_id_assign_by - the name of the Label within the Grid, and at the same time the name of the database field that was used to create this Label and which is now its data source.
- Value - the property of an object (in this case the Label), which can be read and/or modified.
- tasks.user_id_assign_by.Value - fully qualified Value property, which tells the program which object it belongs to. In other words, it is the Value property that belongs to user_id_assign_by field, which in turn belongs to the tasks Grid.
- CCDLookup - CodeCharge function that supports retrieving database value based on a field name, table name, and a condition. Here, this function retrieves the Employee Name (emp_name) from the employees table using the condition that the key (emp_id) equals the current value of the Label.
- DBIntranetDB - the name of the object that defines the database connection that you want to use in the CCDLookup function.
- ToSQL - Connection property that converts a value into the format supported by the database. This property requires a parameter that tells it if a value should be converted to a number (ccsInteger, ccsFloat), text (ccsText, ccsMemo), date (ccsDate), or boolean (ccsBoolean). In this case, this property converts the current Label value to a number that can be used with the CCDLookup function. It is advisable to always use this property together with CCDLookup.
- CCGetUserID - CodeCharge function that returns the ID of the user that is currently logged in.
The whole code reads approximately as follows:
- If a record is being edited: Assign the name of the person who originally submitted the issue to the user_id_assign_by Label, by looking up employee's name from employees table using CCDLookup function that uses the IntranetDB connection and the value of the user_id_assign_by Label.
- If a new record is being created:Assign current user to the user_id_assign_by Label by retrieving his/her name from employees table using CCDLookup function that uses the IntranetDB connection and CCGetUserID function that obtains the current user's ID.