Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 0 down vote accepted

Getting the list name from the url seemed to be a potential solution, but soon I realized that list title can be different than what appears in the url. Finally I used $(".s4-titletext h2 a:first").html() to get the title of the list in the display form. This information is present in the breadcrum. I have blogged about it here.

share|improve this answer
add comment

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

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.

share|improve this answer
    
Hey Vardhaman, This can be one option but I am afraid this won't be an elegant way of doing it. –  Nadeem Yousuf 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 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 Aug 2 '12 at 14:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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