Thursday, June 12, 2014

Check in file using Client script


Share/Save/Bookmark

Here is a simple way of doing few file operations in sharepoint using client script. You can try JQuery for client object model or CSOM or JQuery with SPServices(in my case).

function DiscardCheckOut(url)
{

    var errorMessage = "";

    $().SPServices({
    operation: "UndoCheckOut",
    async: false,
    pageUrl: url,
    completefunc: function (xData, Status) {
         $(xData.responseXML).find("errorstring").each(function() {
         errorMessage = $(this).text();
         });

        $(xData.responseXML).find("faultstring").each(function() {
               errorMessage += $(this).text();
         });

        var undoCheckOutVal= $(xData.responseXML).find("UndoCheckOutResult").text();
        if(undoCheckOutVal == "true")
             alert("Operation success");
        else
            alert("Operation failed:"+errorMessage);
     }
});

}

function CheckIn(furl)
{

   var errorMessage = "";

   $().SPServices({
   operation: "CheckInFile",
   async: false,
   pageUrl: furl,
   comment': "Checked in from checkout list",
   CheckinType: 1,
   completefunc: function (xData, Status) {
       //get errorstring
        $(xData.responseXML).find("errorstring").each(function() {
             message = $(this).text();
        });

       //get fault string
       $(xData.responseXML).find("faultstring").each(function() {
            message +=" "+ $(this).text();
       });

      var checkInResultVal= $(xData.responseXML).find("CheckInFileResult").text();
      if(checkInResultVal == "true")
            alert("Check-in operation success");
      else
            alert("Operation failed:"+errorMessage);
   }
   });
}



Subscribe

No comments:

Post a Comment