Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to add a entry "Archive" to ECB of every document in document library. End user can select to archive the document. I have a custom column "Archive" [Type: check box](values are yes or no) for every document.

I am folowing http://weblogs.asp.net/jan/archive/2009/09/11/customizing-the-sharepoint-ecb-with-javascript-part-3.aspx .

Here Jan wrote for ECB of Task. Chaging the status from ECB. I did some changes to work for Document library. UI showing correctly but nor functionality.

As I am new to this stuff, I got struck at some part of the code..

            var status = $(xData.responseXML).find("z\\:row:eq(0)").attr("ows_Status");

It was explained that the above statement fetch the current value of the field 'Status' and store in var status. Task items have the field 'Status', My documents have the field called 'Archive'. I changed ows_status to ows_Archive, that didn't work for me.

I am pasting the code down, can some one pls explain the code and the changes that I should do further to achive ECB entry.

<script type="text/javascript">

function Custom_AddDocLibMenuItems(m, ctx) { var soapEnv = " \ \ \ " + ctx.listName + " \ \ \ \ \ \ \ \ \ \ " + currentItemID + " \ \ \ \ \ \ ";

var wsurl = ctx.HttpRoot + "/_vti_bin/lists.asmx";

$.ajax({
    async: false,
    url: wsurl,
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: function(xData, status) 
  {
        var status = $(xData.responseXML).find("z\\:row:eq(0)").attr("ows_Archive");

        var menuItem = CASubM(m,"Archive Document");

        var statusOptions = new Array("Yes", "No");

        for(var i in statusOptions) 
    {
          var statusOption = statusOptions[i];
          if(statusOption  != status)
           CAMOpt(menuItem, statusOption ,"changeTaskStatus('" + wsurl + "','" + ctx.listName + "','" + 
                 currentItemID + "','" + statusOption + "');");
        }

}, contentType: "text/xml; charset=\"utf-8\"" });

CAMSep(m);
return false;

}

function changeTaskStatus(wsurl, list, itemid, newstatus) { var batch = " \ \ " + itemid + " \ " + newstatus + " \ \ ";

var soapEnv =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
    <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \
        xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
      <soap:Body> \
        <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
          <listName>" + list + "</listName> \
          <updates> \
            " + batch + "</updates> \
        </UpdateListItems> \
      </soap:Body> \
    </soap:Envelope>";

$.ajax({
    url: wsurl,
    beforeSend: function(xhr) {
        xhr.setRequestHeader("SOAPAction",
        "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
    },
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: function(xData, result) {
        getItemTD(itemid).text(newstatus);
    },
    contentType: "text/xml; charset=utf-8"
});    

}

function getItemTD(itemid) { var tableid = ctx.listName + "-" + ctx.view;

// escape the table id ({ and } should become \{ and \}
tableid = tableid.replace(/{/g, "\\{").replace(/}/g, "\\}");

// select them TR for the item
$itemrow = $("#" + tableid + " table[id='" + itemid + "']").parent().parent();

// select the header row
$headerrow = $(">tr:eq(0)", $itemrow.parent());

// select the table in the header row for the specified column
$idtable = $("th>div>table[Name='Archive']", $headerrow);

// calculate the index of the column, based on the idtable
var columnIndex =$(">th",$headerrow).index($idtable.parent().parent());

// based on the index, let's get the TD
return $(">td:eq(" + columnIndex + ")", $itemrow);

}

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.