Problem setting value to Custom Field

Hi all:

I have a table for adding daily events for people.

I have a date field, and I added a custom field called date_to with the expression ''.

What I need is, if I set date and date_to (i.e. date 2026-02-10 date_to: 2026-02-12), in row_inserting event I add three events (day 10, 11 and 12).

function Row_Inserting(?BaseEntity $oldRow, BaseEntity $newRow): ?bool

{


    $initial_date = $newRow["date"];
    if (null != $this->date_to->CurrentValue) {
        $initial_date= new \DateTimeImmutable($this->date->CurrentValue->format('Y-m-d'));
        $end_date = \DateTimeImmutable::createFromFormat('d/m/Y', $this->date_to->CurrentValue);
        $interval = new DateInterval('P1D'); // Intervalo de 1 día
        $periodo = new \DatePeriod($initial_date, $interval, $end_date);

        $first_date= $initial_date;

        foreach ($period as $day) {

            $date_sql = $dia->format('Y-m-d'); 

            if ($date_sql != $initial_date->format('Y-m-d')) { 
                $sql_prepare = "
                INSERT INTO `asignacion_trabajos` 

                    (`date`, `project`, `names`) 

                VALUES 

                    ('" . $date_sql. "', 

                        '" . AdjustSql($newRow["project"]) . "', 

                        '" . AdjustSql($newRow["names"]) . "', 

                        . "')";

            }

        }


            // 5. Asignar la nueva fecha al registro duplicado

            $newRow["date"] = $initial_date;

    }
   // unset($newRow["fecha_hasta"]); Trying not getting the error
    return true; // Insert the original register
}


The problem is I get the error:
"PHPMaker2026\Db\Entity\Jobs::setDateTo(): Argument #1 ($value) must be of type string, null given, called in \www\partes26\models\JobsAdd.php on line"

The line is:

public function setDateTo(string $value): static
{
    $this->DateTo= RemoveXss($value);        
    return $this;    
}

I’ve tried to unset the field dateTo with no success.

Thanks

That error means, you were trying to assign null value which will trigger the error.

You should always double check your code, especially this part:

$date_sql = $dia->format('Y-m-d');

Where the $dia came from? Shouldn’t it be $day?

1 Like

Ups, sorry, it was a typo while posting to change the variables from spanish into english for better understanding

Thanks mobhar, I’ve checked value is not null before assign, now it’s working