This topic is locked
[SOLVED]

Variable - Before Process and JavaScript Onload events

4/3/2021 6:28:18 PM
PHPRunner General questions
A
abhijit2020 author

I have two tables (e.g. Holidays and Leave) and I would like to use the date column of the holiday table as variable in the Java Script Onload event of add page of the “Leave” table. I tried the following, but it does not work. Any help is greatly appreciated.

Leave Table - Add page events:

Before Process event:

$rs = DB::Query("select * from Holidays");
while ($data = $rs->fetchAssoc())
{
$holidayData["HolidayDate"] = $data["HolidayDate"];
}

JavaScript Onload event:

var ctrlStartDate = Runner.getControl(pageid, 'StartDate');
var ctrlEndDate = Runner.getControl(pageid, 'EndDate');
var ctrlUnits = Runner.getControl(pageid, 'Units');

function func() {
var startDate = new Date(ctrlStartDate.getValue());
var endDate = new Date(ctrlEndDate.getValue());

var holidays = JSON.parse($holidayData["HolidayDate"]); ------ This is not working

…………….
……………..
………………

What works for me. If I replace the above variable, “holidays” with the following, then it works.

var holidays = ['2021-01-01','2021-02-15','2021-04-02','2020-05-24','2020-07-01','2020-09-06','2020-10-11', '2020-12-25', '2020-12-26'];

Thank you in advance.

Abhi

fhumanes 4/4/2021

Hello,

I do not know if I understood what you want to do, but I think I have seen where your mistake is.

Look at these 2 codes and check the difference with which you have:

Before Process event:

$holidayData = [];
$rs = DB::Query("select * from Holidays");
while ($data = $rs->fetchAssoc()) {
$holidayData[] = $data["HolidayDate"];
}
$pageObject->setProxyValue("holidayData", $holidayData);

JavaScript Onload event:

var ctrlStartDate = Runner.getControl(pageid, 'StartDate');
var ctrlEndDate = Runner.getControl(pageid, 'EndDate');
var ctrlUnits = Runner.getControl(pageid, 'Units');

function func() {
var startDate = new Date(ctrlStartDate.getValue());
var endDate = new Date(ctrlEndDate.getValue());
var holidays = proxy['holidayData']
.....
}

I hope it helps you solve your problem.

Greetings,
fernando

A
abhijit2020 author 4/4/2021

Thank you, Fernando. I was able to resolved my issue with the suggested modification. Much appreciated it...Abhi