CheckOutFile

Dec 23, 2009 at 10:17 PM

Need some help with using the CheckOutFile operation. I can't find any discussion about it anywhere. Do I have to use the lastmodified parameter or can it be left off?

Right now I am getting a "Permission Denied" javascript error when I call it like this and not sure why.

$().SPServices({
       operation: "CheckOutFile",
       pageUrl: bookURL,
       checkoutToLocal: false
      });

Any insights would be great.

Thanks. 

Coordinator
Dec 23, 2009 at 11:54 PM

Nick:

Hmm. It looks like the CheckInFile and CheckOutFile operations never made it into the Lists Web Service documentation from the v0.4.0 release notes.  I just added them there.

Here's the code the I used for testing the CheckInFile operation when I first set it up. From the looks of it, your call is good, following the same construct.  Can you give any more details on the error you are getting, what version of the library you are using, etc.?

$(divId).html(waitMessage).SPServices({
  operation: "CheckOutFile",
  pageUrl: testFile,
  checkoutToLocal: "false",
  completefunc: function (xData, Status) {
   var out = $().SPServices.SPDebugXMLHttpResult({
    node: xData.responseXML,
    outputId: divId
   });
   $(divId).html("").append("<b>This is the output from the CheckOutFile operation:</b>" + out);
  }
 });

In case it is helpful (and I'll add it into the documentation as an example), here is a call I used for CheckInFile for a real client project:

// Check in a single document, disable all of the column controls and give a visual cue that it is checked in
 function checkInDocument(obj, pageUrl) {
  var success = true;
  $().SPServices({
   operation: "CheckInFile",
   async: false,
   pageUrl: pageUrl,
   comment: "Checked in during bulk upload",
   CheckinType: 1,
   completefunc: function (xData, Status) {
    $(xData.responseXML).find("errorstring").each(function() {
     alert($(this).text() + " Please save all of your changes before attempting to check in the document.");
     success = false;
    });
   }
  });
  // If we couldn't check the document in, then don't disable the item's row
  if(!success) return success;
  // Disable the item and show it is checked in
  $(obj).closest("tr").each(function() {
   // Mark the item's row so that the user can see it is checked in
   $(this).attr("style", "background-color:#bee1aa");
   // Remove the Check In link
   $(this).find("td:first").remove();
   $(this).prepend("<td class='actiondone'></td>");
   // Disable the Name column
   $(this).find("input:[Title='Name']").attr("disabled", "disabled");
   // Disable the RequestID column
   $(this).find("input:[Title='RequestID']").each(function() {
    $(this).attr("disabled", "disabled");
    $(this).parent().find("img").remove();
   });
   // Disable the Artifact Type column
   $(this).find("input:[Title='ArtifactType']").each(function() {
    $(this).attr("disabled", "disabled");
    $(this).parent().find("img").remove();
   });
   // Disable the AuditRequired column
   $(this).find("[id^='AuditRequired'] input").each(function() {
    $(this).attr("disabled", "disabled");
   });
  });
  return success;
 }
Dec 24, 2009 at 5:11 PM

Thanks for the reply. Below is the complete code for the call:

<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery-1.3.2.min.js"></script> 
<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery.SPServices-0.4.7.min.js"></script> 
<script language="javascript" type="text/javascript">	
     function CheckOutBook(bookURL)
     {
	alert('Got Here!');
	$().SPServices({
		operation: "CheckOutFile",
		pageUrl: bookURL,
		checkoutToLocal: false
	});
	return true;
     }
</script>

I think it has something to do with the jQuery Library. That is where I am getting the "Permission Denied" error.

Coordinator
Dec 24, 2009 at 5:21 PM

This may be an obvious question, but do all users have at least Read Permission on the jQueryLibrary Document Library?  And is it located in the root of the Site Collection?

M.

Dec 24, 2009 at 6:40 PM

Yes, I am the one testing this and am the site administrator, also the jQueryLibrary is in the root of the site.

I know it is accessing the jQuery library because I get a line # where the problem is. I tried to figure out what was going on, but I don't understand what that part of the library is doing.

 

The error points to line: 20 Char: 27021

That would be around this code in the jQuery library:

if(M.username)
{
	J.open(G,M.url,M.async,M.username,M.password)
}
else
{
	J.open(G,M.url,M.async)
}

Am I supposed to send a username and password somehow?

Dec 28, 2009 at 8:02 PM

Okay, I figured out my "Permission Denied" error. I have Alternate Access Mappings configured and the host name in the URL I was accessing the with was different than the URL the script was using to access the SOAP service, it used the actual machine name. If I access the page using the same host name as the machine name, this obviously fixes the cross domain issue.

Now that the request is being sent, I do have another question. Below are the SOAP envelopes for the request and response. The request is successful but the CheckOut fails can you point me in any direction?

<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><CheckOutFile xmlns='http://schemas.microsoft.com/sharepoint/soap/'><pageUrl>/Training Book Library/Coaching to Win.jpg</pageUrl><checkoutToLocal>true</checkoutToLocal><lastmodified></lastmodified></CheckOutFile></soap:Body></soap:Envelope>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CheckOutFileResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><CheckOutFileResult>false</CheckOutFileResult></CheckOutFileResponse></soap:Body></soap:Envelope>
Here again is the code used to send the request:
<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery-1.3.2.min.js"></script> 
<script language="javascript" type="text/javascript" src="/jQueryLibrary/jquery.SPServices-0.4.7.min.js"></script> 
<script language="javascript" type="text/javascript">	
	function CheckOutBook(bookURL, lastDate)
	{
		$().SPServices({
			operation: "CheckOutFile",
			pageUrl: bookURL,
	         		checkoutToLocal: "true"
		});
	}
</script>

I have tried with the checkoutToLocal set to true and false.
Coordinator
Dec 29, 2009 at 12:39 AM

Assuming that bookURL is a valid reference to a file in a Document Library which has Check In/Check Out enabled, things look right.  However, given your issue from the AAM, make sure to pass in the fully qualified path to the file (including http://servername, etc.)

Let me know if that works.

M.

Dec 29, 2009 at 10:16 PM

That was it, I was trying to pass a relative path instead of a full path. Once I passed the full path it worked perfectly.

Thanks!

Coordinator
Dec 29, 2009 at 10:19 PM

Great! So I think that means you've got it working, right?  If you'd be willing, send me the jQuery you ended up with and I'll put it into the documentation as an example so that others will benefit.

Thanks,
M.

Jan 4, 2010 at 4:38 PM

The checkout is working here is the code:

//This link calls the function to check out the document

<a href="javascript:CheckOutBook('http://muskit9238/{@FileDirRef}/{@FileLeafRef}', '{@Modified}');"><b>Request Book</b></a>
Below is the javascript:
<script type='text/javascript'>
function CheckOutBook(bookURL, lastDate)
{
						$().SPServices({
		operation: "CheckOutFile",
		pageUrl: bookURL,
		checkoutToLocal: "false"
	});
						location.reload(true);
}
</script>

Coordinator
Jan 4, 2010 at 5:59 PM

Thanks, Nick!

M.