Write the Frame Scripts
In this procedure, you will create two scripts for the ProjectFrame user frame. One will select records from the project table and update them. Another will provide functionality for the OK and Cancel buttons.
To create a script for the Select and Update buttons
1. Click Tools, Script on the floating menu bar.
The Script Editor opens with the beginning of a frame script displayed.
2. Click at the end of the script and press Enter twice. Then enter the following code:
on click selectbutton =
{
select :project_name = project_name,
:assigned_to = assigned_to,
:level_of_effort = level_of_effort,
:due_date = due_date,
:start_date = start_date,
:date_completed = date_completed
from project
where project_id = :project_id;
}
This code selects the project name and assignee from the project table where the project_id matches what you have entered in the Project ID field on the user frame.
Note: :project_name (with a preceding colon) refers to the field on the frame; project_name refers to the column in the database.
3. Press Enter again and enter the following code:
on click updatebutton =
{
update project
set project_name = :project_name,
assigned_to = :assigned_to,
level_of_effort = :level_of_effort,
due_date = :due_date,
start_date = :start_date,
date_completed = :date_completed
where project_id = :project_id;
}
This code updates the selected project record in the database with the changes entered on the user frame.
4. Click File, Save to save the script and then close the Script Editor.
To create a script for the OK button
1. Select the OK button on the frame.
2. Click Edit, Field Script.
The Script Editor opens with the beginning of a field script displayed.
3. Add the following line between the BEGIN and return; lines:
commit;
Your script should look like the following:
ON CLICK =
BEGIN
commit;
return;
END
This script assigns the commit SQL statement to the OK button, which also closes the frame.
4. Click File, Save to save the script, and then close the Script Editor.
To create a script for the Cancel button
1. Select the Cancel button on the frame.
2. Click Edit, Field Script.
The Script Editor opens with the beginning of a field script displayed.
3. Add the following line between the BEGIN and return; lines:
rollback;
Your script should look like the following:
ON CLICK =
BEGIN
rollback;
return;
END
This script assigns the rollback SQL statement to the Cancel button, which also closes the frame without making any changes to the records in the database.
4. Click File, Save to save the script, and then close the Script Editor.
5. Click File, Save to save the user frame.
You can now compile the frame and run it to test your application.