Row Updating problem

Hello i am using th efollowing code to run q query when th FIELD DISCHARGE change to YES

// Row Updating event
function Row_Updating($rsold, &$rsnew) {
if ($this->Discharge->CurrentValue = “Yes”) {

$id = $this->id->CurrentValue;

$sql = "INSERT INTO contactunlink (id, removalarea)

SELECT employees.id, removalarea FROM employees, unlinkareas WHERE employees.id = ‘" . AdjustSql($id) . "’";
$rs = Execute($sql);

}
}

the problem is that query always run and dont take in count the field Discharge

any idea how fix this

thanks

This part:
$this->Discharge->CurrentValue

should be (assume you want to get the new value of Discharge field in Row_Updating server event):
$rsnew[“Discharge”]

and this part:
$this->id->CurrentValue

shoule be (assume the id is not changed in Row_Updating server event):
$rsold[“id”]

Hello, i change the code as you recommend and move to Row update, now work but i have a new problem now, every time i edit the record the sql trigger again and i need just add the records one time

my code look as :

// Row Updated event
function Row_Updated($rsold, &$rsnew) {
$id = $rsold[“id”];

$sql = “INSERT INTO contactunlink (id, removalarea)


SELECT employees.id, removalarea FROM employees, unlinkareas WHERE employees.id = '” . AdjustSql($id) . "’ " ;

if ($rsnew[“Discharge”] == “Yes”){ // move the record from “candidates” table into “employees” table, only if the new value of “Accepted” is equal to “Y” (meaning Yes)

Execute($sql);


}
}

It is possible avoid this duplication

Thanks

Then you need to check first the related record in “contactunlink” table in that “Row_Updated” server event, whether it has already existed or not.

If it does not exist, then execute your INSERT INTO Sql, otherwise do nothing.

// Row Updated event
function Row_Updated($rsold, &$rsnew) {

$id = $rsold[“id”];
$check_id = ExecuteScalar(“SELECT id FROM contactunlink WHERE id = '” . $id . “'”); // check the id in “contactunlink” table, assume it is string/varchar/char field type
if (empty($check_id)) { // if it does not exist
// execute your INSERT INTO SQL
$sql = “INSERT INTO contactunlink (id, removalarea) SELECT employees.id, removalarea FROM employees, unlinkareas WHERE employees.id = '” . AdjustSql($id) . "’ " ;
if ($rsnew[“Discharge”] == “Yes”){ // move the record from “candidates” table into “employees” table, only if the new value of “Accepted” is equal to “Y” (meaning Yes)
Execute($sql);
}
}

}

Thanks, you ROCk work perfect…