Disabling Buttons on a custom controller

I have a custom controller, and I want to disable certain buttons. If I use the following global method during onShow of the form to make the buttons visible/invisible it works fine:

var currentState = "true"
if ( globals.UserGroupName == "Administrators" )
{
	forms.Navigation.elements.BranchListingButton.visible = currentState
	forms.Navigation.elements.ClassificationListingButton.visible = currentState
	forms.Navigation.elements.ProjectActivityListingButton.visible = currentState
	forms.Navigation.elements.ResponsibilityListingButton.visible = currentState
}
else
{
	forms.Navigation.elements.BranchListingButton.visible = !currentState
	forms.Navigation.elements.ClassificationListingButton.visible = !currentState
	forms.Navigation.elements.ProjectActivityListingButton.visible = !currentState
	forms.Navigation.elements.ResponsibilityListingButton.visible = !currentState
}

However, If I try instead to disable the buttons, it doesn’t work.

var currentState = "true"
if ( globals.UserGroupName == "Administrators" )
{
	forms.Navigation.elements.BranchListingButton.enabled = currentState
	forms.Navigation.elements.ClassificationListingButton.enabled = currentState
	forms.Navigation.elements.ProjectActivityListingButton.enabled = currentState
	forms.Navigation.elements.ResponsibilityListingButton.enabled = currentState
}
else
{
	forms.Navigation.elements.BranchListingButton.enabled = !currentState
	forms.Navigation.elements.ClassificationListingButton.enabled = !currentState
	forms.Navigation.elements.ProjectActivityListingButton.enabled = !currentState
	forms.Navigation.elements.ResponsibilityListingButton.enabled = !currentState
}

Is disabling of buttons on a custom controller not allowed, or am I doing something wrong?

this should work fine.
Does the script work when you manually(form the menubar) execute it?

btw, you can also loop through elements

for( var i=0 ; i<forms.myFormName.elements.length ; i++)
{
forms.myFormName.elements*.myElementName.visible = true*
}

If I execute it manualy, it works!!!

If I run it as part of my Solution opening script, it doesn’t.

I believe that element Objects aren’t reachable yet during solution startup, but maybe Johan should confirm this , being our Java GUI specialist.

What you could try is moving your global script to the Navigation form and attach it to the onLoad property of the Navigation form.

notes:
-as far as I can see, your script doesn’t have to be global?
-onLoad triggers the script only on first time loading of the form.

I have tried moving the method to the Navigation form, still no joy. If I change the statements to .visible, then everything works fine. It just won’t work with .enabled.

I have also tried loading the Navigation form at startup, but unfortunately, this is overridden by the ‘Navigation’ controller being loaded for the first form that is loaded.

It appears that you cannot get to the .enabled state of the controller form. (.visible you can)

i have found the problem
it is because we call en explicit setEnabled(true) when we are showing a form as a controller. I changed this now, but only changed it in the 2.1 version because we have to beta test this if there are side effects, so can’t give you this in a 2.0.4 version.

The work around is calling that script of yours in the main form that is showing the navigation form (on show).