1

I have a SQL table brought into my on-premises foundation (SharePoint 2013) site. The read item and read list functions were normal however I used a stored procedure for the update function. The problem I am having is this will randomly throw an error stating:

Failed to update a list item for this external list based on the Entity (External Content Type) 'proc_UpdateInventoryRecord' in EntityNamespace 'siteURL'. Details: The instance cannot be updated, because there have been changes to the original instance data.

The table is not updated when this error is thrown. Here is my javascript code to try the update:

function updateListItem() {
myShowWaitScreenWithNoClose();

var ID = parseInt(GetURLParameter('TID'));

var WID = $("#Waste").val();

var mDate = new Date();
var user = sp_GetUser();

var siteUrl = _spPageContextInfo.webAbsoluteUrl;

var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('proc_UpdateInventoryRecord');

this.oListItem = oList.getItemById(ID);
    oListItem.set_item('WID', WID);
oListItem.set_item('Modified', mDate.toISOString());
    oListItem.set_item('ModifiedBy', user);

    oListItem.update();

clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

Here is my update procedure:

ALTER PROCEDURE [dbo].[proc_UpdateTrackingRecord]
-- Add the parameters for the stored procedure here
@ID int,
@WID int,
@Modified datetime,
@ModifiedBy nvarchar(50)
AS BEGIN

SET NOCOUNT ON;

-- Insert statements for procedure here

Update wst_inventory SET WID = @WID, Modified = @Modified, ModifiedBy = @ModifiedBy WHERE ID = @ID
END

My question is, am I doing this the right way? Is there an easier/better way? I just started getting into the REST services and can read data from an external list but I read you cannot insert or update an external content type using REST. Any assistance in the right direction would be greatly appreciated.

0

I strongly believe because you are not using a local oListItem object.

Try to define it local as below

var oList = clientContext.get_web().get_lists().getByTitle('proc_UpdateInventoryRecord');

var oListItem = oList.getItemById(ID);
oListItem.set_item('WID', WID);
oListItem.set_item('Modified', mDate.toISOString());
oListItem.set_item('ModifiedBy', user);

oListItem.update();
  • I made this change however I am still getting the error randomly. – StarScr3am77 Aug 5 '16 at 16:58

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.