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'm trying to connect Ribbon to Pages.. This works, javascript get what I need and pass as parameter to my page.. I pass the URL and the SelectedItemsID..

I'm facing a problem:

If I had a List caller (for example) "List - 1" in URL I find "List%20%201" so there is no trace of the "-"

The response I gave to me is to pass the list name from Javascript as a parameter... How can I get this parameter? My custom action code is this:

function enable() {
var items = SP.ListOperation.Selection.getSelectedItems();
var itemCount = CountDictionary(items);
return (itemCount > 0);
}

function CallMe() {
var context = SP.ClientContext.get_current();
this.site = context.get_site();
this.web = context.get_web();
context.load(this.site);
context.load(this.web);
context.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded),
    Function.createDelegate(this, this.onQueryFailed)
);    
}

function onQuerySucceeded() {

var items = SP.ListOperation.Selection.getSelectedItems();
var itemCount = CountDictionary(items);

if (itemCount == 0) return;

var ids = "";
for (var i = 0; i < itemCount; i++) {
    ids += items[i].id + ";";
}

//send a request to the zip aspx page.
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action",  this.web.get_serverRelativeUrl() + "/_layouts/deviantpoint.downloadzip/downloadzip.aspx");

var hfSourceUrl = document.createElement("input");
hfSourceUrl.setAttribute("type", "hidden");
hfSourceUrl.setAttribute("name", "sourceUrl");
hfSourceUrl.setAttribute("value", location.href);
form.appendChild(hfSourceUrl);

var hfItemIds = document.createElement("input")
hfItemIds.setAttribute("type", "hidden");
hfItemIds.setAttribute("name", "itemIDs");
hfItemIds.setAttribute("value", ids);
form.appendChild(hfItemIds);

document.body.appendChild(form);
form.submit();
}

function onQueryFailed(sender, args) {
this.statusID = SP.UI.Status.addStatus("Download as Zip:", 
    "Failed: " + args.get_message() + " <a href='#' onclick='javascript:closeStatus();return false;'>Close</a>.", true);
SP.UI.Status.setStatusPriColor(this.statusID, "red");
}

function closeStatus() {
 SP.UI.Status.removeStatus(this.statusID);
 }
share|improve this question
add comment

2 Answers 2

You can even use GetCurrentCtx() to get context info and get much of information among the list title (name):

var ctx = GetCurrentCtx();
var title =ctx.ListTitle;
share|improve this answer
add comment
up vote 1 down vote accepted

I look around and then arrived to this code:

function getCurrentListName() {
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var currentListGUID = SP.ListOperation.Selection.getSelectedList();
if (currentListGUID === null) {
    var listname = $(".s4-titletext h2 a:first").html(); //requires JQuery to get list name from ribbon breadcrumb
    return listname;
} else {
return currentListGUID;
}
}

It works returning the ID or (if it cannot be found) with the ListName!

share|improve this answer
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.