4

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.

3 Answers 3

0

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.

5
  • Hey Vardhaman, This can be one option but I am afraid this won't be an elegant way of doing it. Jul 19, 2012 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. Jul 19, 2012 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. Jul 20, 2012 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("/") Jul 20, 2012 at 11:11
  • Here is the solution: sharepointnadeem.blogspot.in/2012/08/… Aug 2, 2012 at 14:34
0

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

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 and acknowledge you have read our privacy policy.

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