0

I'm using Sharepoint Plus and want to update multiple list items based on ids.

I have one input text to update only title field and an array of IDs from selected my list items as a function, (to simplify , i have made the list of the ids as the following):

...
<input id="Title" name="Title" type="text">
<script>
var fileds = {};
 $('form').on('submit', function(e) {
   e.preventDefault();
   fileds['Title']= $("#Title").val();
   $SP().list("MyName").update({Title: [fileds] },{
     where:"ID in (34, 45, 55, 33)"
  });
 });    
</script>

if i'm using only one id --> where:"ID = 34" then it is working but i want to update multiple records with the same value from text filed. is there and possibility to do that ? any idea ?

0

You're not doing it right.

It should be:

<script>
 $('form').on('submit', function(e) {
   e.preventDefault();
   var title = $("#Title").val();
   $SP().list("MyName").update({Title:title},{
     where:"ID in ['34', '45', '55', '33']"
  });
 });
</script>

It means that for items with ID #34, #45, #55 and #33, the column 'Title' will be updated with the value title.

You had several issues:

  1. The WHERE clause with IN should have the parameters between [] and not (), and I think the "" are also required (https://aymkdn.github.io/SharepointPlus/lists.html#parse)
  2. The update function must have an one-to-one value, so if you define a field name, it should only have one value

Another possibility is to do pass an array to update():

<script>
 $('form').on('submit', function(e) {
   e.preventDefault();
   var title = $("#Title").val();
   var arrID = [34, 45, 55, 33];
   var toUpdate = [];
   arrID.forEach(function(id) {
     toUpdate.push({ID:id, Title:title})
   })
   $SP().list("MyName").update(toUpdate);
 });
</script>

Your Answer

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

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