Page 1 of 1

Change field on Row_Updating

Posted: Thu Jun 01, 2023 8:52 am
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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 9:14 am
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;

Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 9:36 am
by christ2000

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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 9:59 am
by mobhar

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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:06 am
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?


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:10 am
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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:25 am
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.


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:27 am
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).


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:45 am
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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 10:54 am
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


Re: change enum field on row_updating

Posted: Thu Jun 01, 2023 11:09 am
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.