Change field on Row_Updating

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
christ2000
User
Posts: 519

Change field on Row_Updating

Post by christ2000 »

Hello i have this code on row_updating

if ($rsnew["IssueDate"] !== FALSE)
        $rsnew["notified"] = 0;
    // To cancel, set return value to false




	return TRUE;
}

i need field notified change from 1 to 0 just if field IssuedDate change to a new date, the problem is always go to 0 if and change the field IssueDate or not

any idea what is wrong on my code?

thanks


mobhar
User
Posts: 11709

Post by mobhar »

You should compare between $rsnew and $rsold to check whether the value is changed or not, for example:

if (!empty($rsnew["IssueDate"]) && ($rsnew["IssueDate"] != $rsold["IssueDate"]))
    $rsnew["notified"] = 0;

christ2000
User
Posts: 519

Post by christ2000 »

thanks, i use the code, but now notified just not change to 0 if i chance the date to a new one


mobhar
User
Posts: 11709

Post by mobhar »

Make sure you did not remove return true; line at the bottom of Row_Updating server event.


christ2000
User
Posts: 519

Post by christ2000 »

yes the code look as:

function Row_Updating($rsold, &$rsnew) {

if (!empty($rsnew["IssueDate"]) && ($rsnew["IssueDate"] != $rsold["IssueDate"]))
    $rsnew["notified"] = 0;
    
	return TRUE;
}

do you think maybe is because i am using datepicker on IssueDate?


christ2000
User
Posts: 519

Post by christ2000 »

yes now i change the field on the code to another field name NOTE and then when i type any text on the field the notified got value 0

so is the date field using datepicker, do you think is here a solution for this?

thanks


mobhar
User
Posts: 11709

Post by mobhar »

I see. Well, you need to change your code as follows to investigate:

    // Row Updating event
    public function rowUpdating($rsold, &$rsnew)
    {
        $this->setMessage("Old: " . $rsold["IssueDate"]);
        $this->setMessage("New: " . $rsnew["IssueDate"]);
        return false;
		
        if (!empty($rsnew["IssueDate"]) && ($rsnew["IssueDate"] != $rsold["IssueDate"]))
            $rsnew["notified"] = 0;
        return true;
    }

You should see now the reason, why it always changes the notified field to 0.


mobhar
User
Posts: 11709

Post by mobhar »

Please note that the code I last copied above is from the generated script files under models subfolder. You might see it different between your project (Row_Updating) and the generated one (rowUpdating).


christ2000
User
Posts: 519

Post by christ2000 »

Ok, i have a mistake on the field name the correct is IssuedDate, i miss a "d"

now using your code


$this->setMessage("Old: " . $rsold["IssuedDate"]);
        $this->setMessage("New: " . $rsnew["IssuedDate"]);
        return false;
		
        if (!empty($rsnew["IssuedDate"]) && ($rsnew["IssuedDate"] != $rsold["IssuedDate"]))
            $rsnew["notified"] = 0;
        return true;
}

i got the same problem from start, the field notified go 0 if i change the date or not

the values show from your code on a alert is:

Old: 2023-05-20 00:00:00
New: 2023-05-26


christ2000
User
Posts: 519

Post by christ2000 »

uhh now after change the field on the DB from DateTime to just date, your code work, could be this the problem?

thanks


mobhar
User
Posts: 11709

Post by mobhar »

Well, actually, the reason why I suggested you to display the Old and the New value is just to give you the idea about the difference, especially if you did not change the date to the new one. As you can see, the Old version includes the Time, and the New version does not include the Time.

So, the solution for this matter is simply to adjust the Time to HH:mm:ss from Tools -> Locale Settings of the languages that used by the project, so that it always include the complete Time value in that event. In addition, make sure you have already selected DateTime under Fields setup -> View Tag pane -> Format -> Date/Time format if IssuedDate field type is DateTime.

In other words, you will see now that when you campare the Old and New value in Row_Updating server event, both will always include the complete Time (HH:mm:ss). I think this is the closest approach to resolve the issue above.


Post Reply