Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Need help to have javascript only run once per user when they click button

Where and what do I need to add to this script or button to have it only run once per user. Currently everytime the page is refreshed it adds a new duplicate record to sharepoint list.

Here is a sample of the javascript code - what and where do I add lines in to make it only run once per user and not duplicate every time the page is refreshed


<script type="text/javascript">
 $(document).ready(function()
 {
  ExecuteOrDelayUntilScriptLoaded(AddListItem, "sp.js");
 });
function AddListItem(){
    var ListName = "MyList";
    var context = new SP.ClientContext.get_current(); // the current context is taken by default here
    //you can also create a particular site context as follows
    //var context = new SP.ClientContext('/Sites/site1');
    var lstObject = context.get_web().get_lists().getByTitle(ListName);
    var listItemCreationInfo = new SP.ListItemCreationInformation();
    var newItem = lstObject.addItem(listItemCreationInfo);
    newItem.set_item('Title', 'This is new item');
    // set values to other columns of the list here
    newItem.update();
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
        Function.createDelegate(this, this.onFailure));
 
     function onSuccess() {
 
        alert('Item created: ' + newItem.get_id());
    }
 
    function onFailure(sender, args) {
 
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
}
</script>


<html>
<body>
<input type="button" value="submit" id="btnSub" onclick="AddListItem();" />
    </html>
</body>   

It works and post data to mylist however every time the page is refreshed it adds another record.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda