Hide empty menu item
How do I hide a menu item when the report is empty ? (v2023)
How do I hide a menu item when the report is empty ? (v2023)
You may use MenuItem_Adding server event in which you may use ExecuteScalar()
to select "SELECT COUNT(*) FROM..." to check the number of records in your report.
I tried this code but it doesn't work:
$sSql = "SELECT COUNT(*) FROM `html1`)=0"
if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide
$Item->text = "Deelnemers Conferentiedag";
return FALSE;
} return true;
}
droogers wrote:
$sSql = "SELECT COUNT(*) FROM
html1
)=0"
Wrong SQL.
droogers wrote:
if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide
Wrong syntax.
Oke. I see that the SQL is wrong but what is the good syntax of
if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide
Since you are using v2023, there are no $Item
object in MenuItem_Adding server event. You should use $item
(lower case) instead.
I changed the code but this also didn't work.
function MenuItem_Adding($item)
{
if ($item->Url == "deelnemersconferentiedag" && ExecuteScalar("SELECT COUNT(*) FROM html1
=77") { // <-- menu items to hide
$item->text = "Deelnemers Conferentiedag";
return FALSE;
} return true;
}
Double check your code. It has wrong syntax.
If you write the code that includes the brackets, then make sure the count of open bracket is same as the count of clos bracket.
I changed the code and now it is working:
function MenuItem_Adding($item)
{
if ($item->Url == "deelnemersconferentiedag" && (ExecuteScalar("SELECT COUNT(*) FROM html1")==77)) { // <-- menu items to hide
$item->text = "Deelnemers conferentiedag";
return FALSE;
}
return TRUE;
}