2

So, I've been going through every resource i can find, have tried almost every piece of code I could find on here and using the Microsoft Documentation. I can not figure out that I'm doing wrong. I'm trying to update a field called DispatchStatus in a list called Schedule Orders using REST, but no matter what I try I either get an undefined result in the success function with the field not being updated or I get

{"readyState":4,"responseText":"404 NOT FOUND","statusText":"NOT FOUND"}

returned as an error.

here is the code I'm using:

function updateDelivery(id) {
    var url = "_api/web/lists/GetByTitle('Scheduled Orders')/items(" + id + ")"
    var itemMetadata = {
      '__metadata': {
          'type': getListItemType('Scheduled Orders')
      },
      'DispatchStatus': document.getElementById(id).value
  };
  updateL(url, itemMetadata, checkresult);
}
function updateItem(url, itemMetadata, callback) {
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        data: JSON.stringify(itemMetadata),
        type: 'POST',
        contentType: 'application/json;odata=verbose',
        headers: {
            'X-HTTP-Method': 'MERGE',
            'X-RequestDigest': $("#__REQUESTDIGEST").val(),
            'Accept': 'application/json;odata=verbose',
            'IF-MATCH': '*'
        },
        success: function (data) {
            callback(data);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}
function getListItemType(name) {
    var ret = "";
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + name + "')?$select=ListItemEntityTypeFullName"
    $.ajax({
        url: url,
        method: "GET",
        async: false,
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function (data) {
            ret = data.d.ListItemEntityTypeFullName
        },
        error: function (error) {
           alert(JSON.stringify(error));
        }
    });    
    return ret;
}

This seems like it should be a simple task, am I missing required data? Do I need to copy over all the previous data in the item? Or do I need to go about updating a list item differently?

1

I figured it out. Turns out that it was working the entire time but IE apparently has issues recognizing

var a = b = c = d = "";

insted of

var a = "";
var b = "";
var c = "";
var d = "";

So in IE, which is the browser I have to develop this for, it looked like it wasn't working because that value that was being updated was not being picked up. When I looked at the app in Chrome and noticed that everything was working i realized it was not my REST call but instead a problem with the browser. I tracked it down and now it finally works in IE. Yet another thing that IE causes to break but everything else on all other browsers works just fine.

Update

So it looks like IE was getting confused and setting var c to a read only value. It was being assigned the empty string and then unable to be changed. I have no clue why it was doing this and why only that one variable. Very strange bug indeed. Anyone have any thought as to why/how this was happening?

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.