I'm adding a Context Menu (ECB) item to a SharePoint Online list using the code example found here.
My code works, the problem is it adds a new item each time the page is refreshed, not overwriting the previously added item, so I get duplicates. How to prevent this?
My code, added via Script Editor on the SharePoint list page:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $( document ).ready(function() { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomUserActionToECB); }); function AddCustomUserActionToECB() { var clientContext = new SP.ClientContext(); var oWeb = clientContext.get_web(); var oList = oWeb.get_lists().getByTitle('ProjectCommunications'); var userCustomActionColl = oList.get_userCustomActions(); var oUserCustomAction = userCustomActionColl.add(); oUserCustomAction.set_location('EditControlBlock'); oUserCustomAction.set_sequence(100); oUserCustomAction.set_title("Add Attachment"); oUserCustomAction.set_url("myURL"); oUserCustomAction.update(); clientContext.load(userCustomActionColl); clientContext.executeQueryAsync(); } </script> How to prevent duplicate entries?
