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.


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:


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.

  • Hey Vardhaman, This can be one option but I am afraid this won't be an elegant way of doing it. – Nadeem Yousuf-AIS Jul 19 '12 at 15:09
  • Did you check whether you have the "Source" query string parameter? If not, then I am afraid you will have to resort to the other option. – Vardhaman Deshpande Jul 19 '12 at 15:28
  • I do have the source parameter but the problem is I still have to do string manipulations as there is no method available in Client Object model which takes List Url as parameter, we can either use Title or GUID of the list. – Nadeem Yousuf-AIS Jul 20 '12 at 4:26
  • Then I guess string manipulation is the only option you have. It will be easier with the "Source" parameter because you will have to fetch the string from the lastIndexOf("/") – Vardhaman Deshpande Jul 20 '12 at 11:11
  • Here is the solution: sharepointnadeem.blogspot.in/2012/08/… – Nadeem Yousuf-AIS Aug 2 '12 at 14:34

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()
  • As mentioned in the question SP.ListOperation.Selection returns null in the display page. – Nadeem Yousuf-AIS Sep 13 '12 at 13:37
  • Must have overlooked that, sorry. – Jasper Sep 18 '12 at 9:19

The ListId can be retrieved using _spPageContextInfo.pageListId in the display form of a list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.