i have Table “project_sti” with field “id” as primary key, field “project_id” as a foreign key that references the primary key in the master table, field “sti_org_id” and field “role“.
So in PHPRUNNER, NO DUPLICATE ENTRY based on fields “project_id” AND “sti_org_id” AND “role“. Message will appear “Data already Exist”
To enforce the rule in PHPRunner that prevents duplicate entries in the child table based on the combination of project_id, sti_org_id, and role, and to show a custom message “Data already exists”, you can follow these steps:
Using the Before Record Added/Updated Event
- Go to Events in PHPRunner for your
project_stitable. - Select the Before Record Added and Before Record Updated events.
- Add the following PHP code:
// Check for duplicate entry
$project_id = $values[‘project_id‘];
$sti_org_id = $values[‘sti_org_id‘];
$role = $values[‘role‘];
$rs = DB::Query(“SELECT * FROM project_sti WHERE project_id= ‘$project_id‘ AND sti_org_id= ‘$sti_org_id‘ AND role = ‘$role‘”);
if($rs->fetchAssoc())
{
$message = “Data already exists.”;
return false; // This will stop the record from being added/updated
}