Page 1 of 1

Hide empty menu item

Posted: Sat Jan 28, 2023 3:54 pm
by droogers

How do I hide a menu item when the report is empty ? (v2023)


Re: Hide empty menu item

Posted: Sat Jan 28, 2023 8:50 pm
by arbei

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.


Re: Hide empty menu item

Posted: Mon Jan 30, 2023 4:59 am
by droogers

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;

}

Re: Hide empty menu item

Posted: Mon Jan 30, 2023 9:48 am
by arbei

droogers wrote:

$sSql = "SELECT COUNT(*) FROM html1)=0"

Wrong SQL.

droogers wrote:

if ($Item->Url == "deelnemersconferentiedag" && ExecuteScalar($sSql) { // <-- menu items to hide

Wrong syntax.


Re: Hide empty menu item

Posted: Mon Jan 30, 2023 3:51 pm
by droogers

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


Re: Hide empty menu item

Posted: Mon Jan 30, 2023 4:45 pm
by mobhar

Since you are using v2023, there are no $Item object in MenuItem_Adding server event. You should use $item (lower case) instead.


Re: Hide empty menu item

Posted: Tue Jan 31, 2023 1:38 am
by droogers

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;
}


Re: Hide empty menu item

Posted: Tue Jan 31, 2023 6:22 pm
by arbei

You may read and learn Counting Rows.


Re: Hide empty menu item

Posted: Wed Feb 01, 2023 8:09 am
by mobhar

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.


Re: Hide empty menu item

Posted: Fri Feb 03, 2023 1:29 am
by droogers

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;
}