How do I enable/disable a ribbon button in the Display form?
-
09-12-2019 - |
Question
I want to enable/disable a ribbon button in display form of a list based on whether versioning is enabled or not.
In the EnabledScript
of CommandUIHandler
, I am specifying a javascript function which will check the versioning in the given list.
The problem is that there seems to be no way of getting reference of the current list as tokens like {ListId}
are not available in EnabledScript
. I also can't use SP.ListOperation.Selection
as it reurns null, which is quite obvious.
Solution 3
The ListId
can be retrieved using _spPageContextInfo.pageListId
in the display form of a list.
OTHER TIPS
Since the code from EnabledScript will be executed on the page, You can fetch the name of the list from the window.location.href
of the page. You can probably get the name by doing some string manipulations to the window.location.href
by using substr
or substring
JS functions.
Example: Your window.location.href
will be something like:
http://servername/Lists/YourList/Forms/DispForm.aspx?ID="YoutItemId"
You can fetch "YourList" if you know that the "servername/Lists" and "Forms/DispForm.aspx" are going to be constant.
Another option is to check whether the window.location.href has the Source
query string parameter. If it's present, it should directly give you the list url.
The default JavaScript context functions don't work? I.e.
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var currentListId = SP.ListOperation.Selection.getSelectedList()