0

I have been trying to research and troubleshoot this issue for months now. I cannot find anything, so hopefully, this is an easy fix.

As a note, I am unable to make the column unique as sometimes, a duplicate is okay when user-submitted.

In my add-in, I am using JavaScript and for saving the item I call

...addItem(listCreationInformation);

After I set the items, I call

load() and executeQueryAsync() functions.

Tracing with breakpoints and debugging via browser tools, it only executes the function once when saved. However, When I go to the list, sometimes I see one has been added. Other times, I will see from 2 to 10 duplicates created milliseconds apart from each other. This tells me that after the information is sent back to the server for processing, SharePoint, not my add-in is creating duplicates. Not sure why or where to go from here.

Below is a more detailed example of code:

HTML

<input type="submit" value="Save" onClick="SaveInfo()" />

JavaScript

function SaveInfo(){
    var webCTX = new SP.ClientContext.get_current();
    var hostWebUrl = myhostweburl;
    var hostCTX = new SP.AppContextSite(webCTX, hostWebUrl);
    var list = hostWeb.get_lists().getByTitle("MyList");
    var listCreationInformation = new SP.listItemCreationInformation();
    var oListItem = list.addItem(listCreationInformation);
    oListItem.set_item("Title", newTitle);
    oListItem.set_Item("Description", newDescription);
    ...
    oListItem.update();
    oListItem.load(oListItem);
    webCTX.executeQueryAsync(function(){
        alert("Saved."); 
        window.location = "Default.aspx";
    },onError);
};

It only runs through this code once when saved, but save multiple, but only sometimes.

  • Could you submit more code please? – MickB Jun 5 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.