This topic is locked

Filter panel: setting a field value via some function

9/29/2022 8:31:52 AM
PHPRunner General questions
H
Henny Sol author

I want to set the value of a field on the filter panel to a value that is returned by some function (for example filtering on the month number of the current date)

The only places I can find where I can update the url link of the menuitem are Style/MenuEditor and Designer/CommonPages/menu (field URL param).

To be precise I want to do something like this:

$thismonth = date("m");
$urllink = $urlink . "f=(month~equals~" . $thismonth . ")";

I already tried to update the link of the menuitem in the MenuEditor by adding "f=(month~equals~<?php echo date("m"); ?>) but that does not work.

Best regards,
Henny Sol
(PHPRunner 10.8 build 39787 x64)

H
Henny Sol author 9/29/2022

I placed the following code in ModifyMenyItem event (note I have a field begd in my Acties table that contains the entrydate of the action):

// Place event code here.
$tody = date("d-m-Y");
$filter = "f=(begd~equals~" . $today . ")";
if($menuItem->getLinkType() == 'Internal')
{
if ($menuItem->getTable() == 'Acties')
{
$menuItem->setParams($filter);
}
}
// Use "Add Action" button to add code snippets.
return true;

I checked using the echo command that the params are correctly set but nevertheless in the url in my browser I only see the Acties_list.php and not the added params.

Sergey Kornilov admin 9/29/2022

I can see that there is a variable that is misspelled, $today vs $tody. Not sure if this matters.

H
Henny Sol author 9/29/2022

In the actual code the $tody variable is written as $today (I made some error while pasting the code).

H
Henny Sol author 9/30/2022

Today I saw that my coding worked OK when I click on Acties in the menu I created in Style/MenuEditor.

When I click on Acties in the menu I created in Designer/CommonPages/Menu I can see (using the echo command) that the Params are correctly updated but nevertheless the resulting url still shows the old params. I guess this is a bug (?).

Just to be sure my actual code in the ModifyMenuItem event (which apparently is executed in BOTH cases!) is:

$vandaag = date("d-m-Y");
$filter = "f=(begd~equals~" . $vandaag . ")";
if($menuItem->getLinkType() == 'Internal')
{
if ($menuItem->getTable() == 'Acties')
{

// echo $menuItem->getTable();
// echo $menuItem->getParams() . "oud";
$menuItem->setParams($filter);
// echo $menuItem->getParams() . "nieuw";
}
}