Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda