This topic is locked

Copy record with updated Date and due date

5/31/2024 2:36:27 PM
PHPRunner General questions
Mark Kramer author

I have an add page with this Javascript Onload event that works fine in the add mode. It inserts today's 'Date' and calculates 'DueDate' 120 days in the future from today. What I'm trying to accomplish is to Copy the record to a new record with the updated Date and the new calculated DueDate. I created a custom view and added the script below to the JavaScript Onload event on this views Add page. For some reason it does not populate the record Date with today and therfor the calulated DueDate doesnt work either. How do I go about this? I've hit that wall and cannot figure out what i'm missing.

var d1 = Runner.getControl (pageid, 'Date');

var d4 = Runner.getControl (pageid, 'DueDate');

//var da2 = parseInt ();
var da2;

function func() {

$da2=120; // Cycle for room pm "120" = days


function addDays(theDate, days) {
return new Date(theDate .getTime() + days 2460601000);
var newDate = addDays(new Date(), da2); //$da2 sets number of days


d1.on('change', func);

Any thoughts, suggestions would greatly be appreciated.


Sergey Kornilov 5/31/2024


a few things are not clear. Do you use the built-in Copy function? Not sure how to decipher "Copy the record to a new record with the updated Date". What is "updated Date" here?

Mark Kramer author 5/31/2024

I used the built in copy but I'm not sure if it is the best option I could not figure out how make a custom button work for this. It is basicly a Preventive Maint Program.

What I am trying to achieve is when I click the builtin copy icon or a custom button, it copies the old record and changes the "Date" field (updated date) in the new record to the current date then the 'DueDate" is calcualted 120 in the future.

Sergey Kornilov 5/31/2024

Okay, lets assume that you use the built-in Copy function.

Somehow you need to implement the code that changes the "Date" field (updated date) in the new record. At the same time, after you calculated "Date" field, you can also calculate the second date field.

I recommend to use Add page: Process Record Values event for this purpose:

Mark Kramer author 5/31/2024

I'll try it and let you know.


Mark Kramer author 6/12/2024

Ok .. I tried a new approach with decent success but I am getting a very strange error. It is a sever error [] and that's it.

Here is my scenerio an then the code... I have a list page with a button that takes, the RoomNumber and of the current record and autofills the RoomNumber field on the new Add record. During this time, I take todays date and calculate it 120 days out to get a DueDate for the room for next time it needs service. This works as should and both fields autopopulate in the new record. Somewhere between button click and the redirect, it throws the error [] then continues on to the record like it should. It all works but the %#@^#^ error!

Here is my event code:
List Page Button ( Server )

global $conn;

$record = $button->getCurrentRecord();

$roomNumber = $record["RoomNumber"];
$date = date("Y-m-d H:i:s");
$dueDate = date("Y-m-d H:i:s", strtotime("+120 days"));

// Create a query string to pass data via URL
$queryString = http_build_query([
"RoomNumber" => $roomNumber,
"Date" => $date,
"DueDate" => $dueDate

// Generate the URL
$url = "RoomPMEng_Due_add.php?" . $queryString;

// JavaScript to redirect
echo "<script>window.location.href='$url';</script>";

Add Page
// Process Record Values Event
if (isset($_GET['RoomNumber']) && isset($_GET['Date']) && isset($_GET['DueDate'])) {
$values['RoomNumber'] = $_GET['RoomNumber'];
$values['Date'] = $_GET['Date'];
$values['DueDate'] = $_GET['DueDate'];

I've tested the code on different PHP code checkers and all say it is good..... I just can't figure out what it is looking for to throw the error..

Thanks in advance..


Sergey Kornilov 6/12/2024

You cannot send anything to the output from button's server code, it will break the whole button execution process.

More reading: