Error handling with UpdateListItems

Jul 17, 2012 at 3:54 PM

I use UpdateListItems a lot, and the error handling has typically comprised some version of:

if(Status != 'success') alert("error: " + xData.responseText);

Recently, I discovered that the write operation is actually failing, but it still reports 'success'.

The reason for the recent failure is worth an article on its own, but confining myself to determining when an error has occurred is the current point. Here is what I've come up with:

completefunc: function(xData, Status) {
  var strError = $(xData.responseXML).SPFilterNode('ErrorText').text();
  if(strError != "") {
    $("#showData2").append("

Error updating: " + $(xData.responseXML).SPFilterNode('z:row').attr("ows_PBCOrig") + " " + strError + "

"); } ... //whatever else you're doing }

The point is that if the write has failed, then there will be <ErrorCode> and <ErrorText> nodes present. If it is successful, then they don't appear and the branch is not executed.

What you actually display as your error message is, of course, entirely dependent upon your own situation.

My use of an error statement seems the only thing I can do. It is interesting that the response will include the _current_ values (ie, the ones that did not get written over by the ones you intended), and I played with comparing the intended values against the actual values. This does work but seems overkill, at least for my current use.

Coordinator
Jul 17, 2012 at 4:03 PM

"success" indicates that the .ajax() call was successful, not that the write (or any other operation) was successful.

It's a tough call to know what to do it there's a real error. I'm always loathe to pop up "Contact your administrator" errors, since that's basically worthless. One thing that I have found to be true, though: if your call has good XML, the likelihood of a failure is something very, very low.

M.

Jul 17, 2012 at 6:09 PM

I, too, have not handled "real" errors before, but this is a very serious one. The application (at this point) purportedly writes a couple dozen rows _updating_ an existing set of rows. In fact, nothing has happened but you, the operator, don't know that.

Let me say something about how this error came to be. I upload an Excel spreadsheet into SP. I then copy much of that data to another list, and from there the updating action happens on still another list. It took a while, but here is what I discovered.

When SP uploads a spreadsheet, it does so by looking at all the values within each column, then deciding what the data type of the SP version of that column should be. When I devised this application, there were date values in the Excel sheet, so Date & Time became the SP data type. For some internal processing, I had to devise a function to fiddle with those date values. Fine.

Last week, I went again through the import process and subsequent processing, but eventually the client came and said What happened? What had happened was that whoever worked the Excel spreadsheet entered a date as "July 2,2012" No space after the comma. SP said, Oh, that must be text. To the observer, it looks like a date, but inside the date-based function I had written crunches the date value into something unusable. Thus, the normally fine process at the end of all this attempts to write a nonsense value to a date field, and QUIETLY exits without having done so.

Because the application is run only by administrators, the notion of showing error messages is not a problem.

Coordinator
Jul 17, 2012 at 7:08 PM

I see where you are on this. The Excel thing throws some variables into things that you can't control.

FWIW, I've done similar things, but rather than importing each time, I go into Datasheet view, delete the old data, and paste in the new. That means that the list structure stays the way we set it up, and we get errors if any of the data doesn't conform.

M.

Mar 22, 2013 at 1:00 AM
This is out the point discussed here (and I apologize in advance) but do you have a blog describing your work to create that Excel-to-SP import utility? I've been recently challenged to find a way to periodically import data from one of our forms (simple Excel sheet with specific column names). I gave my users a brief lesson in how to use the datasheet views but I'd much rather have an utility to do some business logic in the background.
Mar 22, 2013 at 1:23 AM
Edited Mar 22, 2013 at 1:43 AM
I have a jqGrid that shows records from a database, users can select one or more to make a copy of those in a list in our site. In my case I had to implement error handling to let users know when the record they choose to create already existed.

Let me try to explain, it was very annoying at the beginning because there was no error message and the record "sometimes" got to the list and other times didn't. I found a 0x80040e2f error value in the ErrorCode tag and doing a deeper search in Google found that the "Title" field value cannot be repeated (preexist in the list), it works like a unique key. Strange thing to see that if you try to create a repeated record (having the same value for the "Title" field) using the New Form for the list you will not get this error.

Image
completefunc: function(xData, Status) {
   var errXML = xData.responseXML;
   var errRows = errXML.getElementsByTagName("ErrorCode");
   if(jQuery(errRows).text() === '0x80040e2f') {
      alert('The record you selected cannot be created because it already exists in the list');
      return false;
   } else {
      // continue redirecting the user to the recently created record.
   }
}
Mar 22, 2013 at 4:11 PM
I have a jqGrid that shows records from a database, users can select one or more to make a copy of those in a list in our site. In my case I had to implement error handling to let users know when the record they choose to create already existed.

Let me try to explain, it was very annoying at the beginning because there was no error message and the record "sometimes" got to the list and other times didn't. I found a 0x80040e2f error value in the ErrorCode tag and doing a deeper search in Google found that the "Title" field value cannot be repeated (preexist in the list), it works like a unique key. Strange thing to see that if you try to create a repeated record (having the same value for the "Title" field) using the New Form for the list you will not get this error.
completefunc: function(xData, Status) {
   var errXML = xData.responseXML;
   var errRows = errXML.getElementsByTagName("ErrorCode");
   if(jQuery(errRows).text() === '0x80040e2f') {
      alert('The record you selected cannot be created because it already exists in the list');
      return false;
   } else {
      // continue redirecting the user to the recently created record.
   }
}
Coordinator
Mar 22, 2013 at 6:31 PM
I just did a simple test because what you said didn't sound right. I can use UpdateListItems in Custom List and add as many items with an identical Title value as I want. There's no uniqueness required.

Perhaps you've set something to require the uniqueness? In 2010, there is a setting for this on the column settings page: "Enforce unique values:".

M.
Mar 22, 2013 at 6:40 PM
I have a jqGrid that shows records from a database, users can select one or more to make a copy of those in a list in our site. In my case I had to implement error handling to let users know when the record they choose to create already existed.

Let me try to explain, it was very annoying at the beginning because there was no error message and the record "sometimes" got to the list and other times didn't. I found a 0x80040e2f error value in the ErrorCode tag and doing a deeper search in Google found that the "Title" field value cannot be repeated (preexist in the list), it works like a unique key. Strange thing to see that if you try to create a repeated record (having the same value for the "Title" field) using the New Form for the list you will not get this error.
completefunc: function(xData, Status) {
   var errXML = xData.responseXML;
   var errRows = errXML.getElementsByTagName("ErrorCode");
   if(jQuery(errRows).text() === '0x80040e2f') {
      alert('The record you selected cannot be created because it already exists in the list');
      return false;
   } else {
      // continue redirecting the user to the recently created record.
   }
}
Mar 22, 2013 at 6:46 PM
Hi Marc,
I'm using WSS 3.0 and started with a blank site, then created customized lists. The first time that error happen it confused me a lot so I started searching in Google for "error code 0x80040e2f" and some of the results suggested a Primary Key constraint error.

It also happened when I wanted to clone a record, I was getting this same error over an over again, so I decided to create a timestamp text and add it to the value in the Title field, that got me through.
Coordinator
Mar 22, 2013 at 7:04 PM
I'm not sure why you'd see that. My test was also in WSS 3.0, so I can't think why you'd be getting that error. The errors with the Web Services are notoriously misleading, so it was probably telling you something different than what it actually said.

M.
Mar 22, 2013 at 7:19 PM
Hi Marc,
I'm using WSS 3.0 and started with a blank site, then created customized lists. The first time that error happen it confused me a lot so I started searching in Google for "error code 0x80040e2f" and some of the results suggested a Primary Key constraint error.

It also happened when I wanted to clone a record, I was getting this same error over an over again, so I decided to create a timestamp text and add it to the value in the Title field, that got me through.