Home › Forums › General discussion › Save all items in a list
- This topic has 4 replies, 2 voices, and was last updated 8 years, 8 months ago by Alexander Bautz.
-
AuthorPosts
-
-
March 10, 2016 at 17:28 #10724
I was wondering if there is a javascript function that would run through a whole list and save each Item.
I made modifications to a lookup list. We changed our naming convention for this list so each of the items changed. This change does not take effect on any of the lists that have already used this lookup until the item is opened and saved, then the system flows it to the item.
Any ideas?
Thanks!
Lana -
March 20, 2016 at 15:38 #10819
Hi,
I’m sorry, but I’m not sure I completely understand. Is this a standard lookup field, or have you used the “cascading dropdown” or “spjs-lookup” features in DFFS?Is it the lookup list item you need to open and save, or is it all the lists looking up values from the lookup list?
Alexander
-
March 29, 2016 at 12:17 #10932
Hi,
Lets go at this from another perspective. I want to add a column to a list, use a rule to Set Default Value to equal another field on the form….how do I get that to implement for the whole list, without opening and saving each item in the list?
Thanks!
Lana -
March 30, 2016 at 21:12 #10949
If this is a one time operation, using DataSheet / quick edit would possibly by easiest?, but the script to do this update is quite easy to write.
Basically you need to query all items with the correct value in the “donor” field, and iterate over these to set the value in the new field.
I can create this script, but the performance depends on how many items you have in the list – can you give me a ballpark figure on the item count?
Alexander
-
April 1, 2016 at 23:41 #10997
Hi,
Add this script to a HTML form web part or a Script editor web part in a list view of the list you want to update. You must change the script src to the two scripts.:<label>From column </label><input type="text" id="spjs_colA" value=""> <label>To column </label><input type="text" id="spjs_colB" value=""> <input type="button" onclick="doUpdateColumn()" value="Copy val from col A to col B"> <script type="text/javascript" src="https://spjsblog.sharepoint.com/DFFS/SPJS/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="https://spjsblog.sharepoint.com/DFFS/SPJS/DFFS/spjs-utility.js"></script> <script type="text/javascript"> function doUpdateColumn(){ var a = $("#spjs_colA").val(), b = $("#spjs_colB").val(), res, uRes, data, count = 0; if(a === "" || b === ""){ alert("Please fill in both fields"); }else{ if(!confirm("Write the value from column \""+a+"\" to column \""+b+"\"?\n\nPlease note that the page will FREEZE while this operation runs. If you want to follow the progress, open a new brower window and use this to look at the progress by inspecting columne \""+b+"\" for change.")){ return; } res = spjs_QueryItems({"listName":_spPageContextInfo.pageListId,"query":"<Where><IsNotNull><FieldRef Name='"+a+"' /></IsNotNull></Where>","viewFields":[a,b]}); $.each(res.items,function(i,item){ if(item[a] !== item[b]){ data = {}; data[b] = item[a]; uRes = spjs_updateItem({"listName":_spPageContextInfo.pageListId,"id":item.ID,"data":data}); if(!uRes.success){ alert(uRes.errorText); return false; }else{ count += 1; } } }); alert("Done updating "+count+" items."); location.href = location.pathname; } } </script>
Hope this gets you started.
Alexander
- This reply was modified 8 years, 8 months ago by Alexander Bautz. Reason: Removed default values in inputs
-
-
AuthorPosts
- You must be logged in to reply to this topic.