I have a sharepoint list with two columns, one with one time codes and the other one is yes/no

Like this:


So what I'm trying to achieve is with javascript/jquery have a page where you could click a button and receive the next available code in the list and mark that code's used column to Yes. So next time you click the button you get the next code which aren't marked as used. This is for a internal service and a user can request a code themselves instead of contacting an administrator.

1 Answer 1


Try to use this rest api endpoint:

/_api/lists/getbytitle('list title')/items?$select=CODE&$filter=USED eq 'NO'&$orderby=ID&$top=1

It will only return the unused code with the smallest ID.

  • Thanks, and to update the Used value to Yes after getting the Code what's the best approach?
    – SuperDOS
    Commented Mar 23, 2021 at 7:33
  • You could use rest api to update the list item too.The official document on rest updating list item:docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/… Demo:c-sharpcorner.com/article/…
    – Amos
    Commented Mar 23, 2021 at 8:47
  • Thanks will look into the rest api more carefully.
    – SuperDOS
    Commented Mar 23, 2021 at 9:24
  • If my answer helps you, you could mark it as the answer and vote for it. Thank you :).
    – Amos
    Commented Mar 23, 2021 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.