Comments (10)
I'm on vacation in another country. I cannot really help for now.
from sharepointplus.
I encountered this challenge as well and while I haven't looked at the latest rev of this library, I think my solution may work for you.
var UPDATES = $scope.configurations.map(function(x){
return new Promise(function(ok, reject) {
if(updateCheck){
$SP().list("List Name").update({
ID:43, Title:"Ok"
}, {
success:function(items) {
ok(items)
}
});
}else{
$SP().list("List Name").add({
Title:"Ok"
}, {
success:function(items) {
ok(items);
}
})
}
})
})
Promise.all(UPDATES).then(function(data) {
console.log('ALL UPDATES OK')
})
Had to use this for a bunch of calls to and API nested within another call - I needed a babel polyfill for Promises as I was using IE11.
I haven't tested this exact code so might not work but the idea is to map and return a bunch of Promises and use Promise .all
then to tell when it is all done
from sharepointplus.
The last version supports Promise. Also check this link : https://blog.kodono.info/wordpress/2017/04/13/resolve-promise-one-after-another-in-sequence/
from sharepointplus.
Thanks to all. I'm gonna try your solutions and will tell you..
from sharepointplus.
@buddythumbs excuse me, if there is an error in the update for example, what happens?
if we add the optional error function what will happen?
from sharepointplus.
Hey @micuentadecasa,
Sorry, forgot to put that in there. I would maybe do something like the following:
var UPDATES = $scope.configurations.map(function(x){
return new Promise(function(ok, reject) {
if(updateCheck){
$SP().list("List Name").update({
ID:43, Title:"Ok"
}, {
success:function(items) {
ok(items)
}, error:function(items){
reject(items)
}
});
}else{
$SP().list("List Name").add({
Title:"Ok"
}, {
success:function(items) {
ok(items);
}, error:function(items){
reject(items)
}
})
}
})
})
Promise.all(UPDATES).then(function(data) {
console.log('ALL UPDATES OK')
}).catch(function(items){
console.error(items)
})
(Verify the syntax on the SP Plus docs for adding both success and error)
from sharepointplus.
Thanks @buddythumbs , your code works like a charm but there was a problem with my first explanation, in fact Promise.all expect all the promises but it doesn't stop execution until all promises are returned that is what I need, I need to wait until all is done or not.
I've seen that for this I will have to work with generators..
from sharepointplus.
Dear all, I have tried with generators also but no luck (it doesn't stop the execution), I think will be a good idea when @Aymkdn has time to create an article about:
- present the idea from @buddythumbs
- explain when using sharepointplus functions with an array in $SP().list("List Name").update(array - if it is done in the order of the array of it is done async with any item of the array
- propose a solution to do updates or insert in an order (we can have needs of making inserts in an order).
- propose a solution to do different operations and not returning until all is done (and stop the execution of the rest of code until we return from this function).
Note:
I know this is out of the library, is more a javascript question but I think it is interesting to people using this library.
In addition know that in ES7 javascript there is an await that can be used for this but it seems it doesn't work in the actual browsers...
from sharepointplus.
explain when using sharepointplus functions with an array in $SP().list("List Name").update(array) - if it is done in the order of the array of it is done async with any item of the array
It's done in the order you provide the items into the array.
Example of what you can do:
var add=[], upd=[];
for (var i=0; i<total; i++) {
if (MyCriteria === true) add.push({MyField:"something"});
else upd.push({MyField:"something"})
}
// Once you have finished all your checks,
// you can proceed with the add/update operations into the list
// → Example with SharepointPlus v4.0 and Promises
// → in that case the both operations will be done at the same time
// DISCLAIMER: I didn't test it and the Promises stuff in SharepointPlus is new so it might not work as excepted
Promise.all([
$SP().list("YourList").add(add),
$SP().list("YourList").update(upd)
]).then(function() {
// all add and update operations have been completed
})
// or without Promise and if you want to start with ADD and then with UPDATE you can do:
$SP().list("YourList").add(add, {
after:function() {
alert("ADD operations completed");
$SP().list("YourList").update(upd, {
after:function() { alert("UPDATE operations completed") }
})
}
})
Also, if it doesn't answer your question, you need to provide your code and then I should be able to provide a better answer.
from sharepointplus.
from sharepointplus.
Related Issues (20)
- getWorkflowID does not work in NodeJS HOT 6
- stopWorkflow does not work inside NodeJS : ReferenceError: document is not defined HOT 16
- $SP().getUserInfo POST Status 500 error HOT 2
- .get() paging and rowlimit not working for SPO document library HOT 7
- need an example for add.options.packetsize HOT 6
- setReadOnly:Error HOT 3
- Observables with Sharepoint+ HOT 1
- Getting the count of rows from a list HOT 2
- Error from server-side node HOT 4
- addAttachment contextinfo 404 error HOT 19
- Get Column Type HOT 1
- Translate SharePoint column names HOT 2
- distribution list members HOT 2
- Unable to getContentTypeInfo HOT 3
- The site URL passed in the setup object is always ignored in the isMember(...) function HOT 6
- RequestError: Error: tunneling socket could not be established, cause=Client network socket disconnected before secure TLS connection was established HOT 1
- sp.lists gives `ReferenceError: window is not defined` HOT 2
- sharepointplus with sp-rest-proxy HOT 11
- incorrect hasREST function behavior for Sharepoint Online / 365 HOT 2
- joins HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharepointplus.