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();
    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);

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


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() {

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;

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!

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.