var dataObj = [];
// Get data service
VSS.getService(VSS.ServiceIds.ExtensionData)
// the callback on the next line returns x` promise, which the JavaScript engine will follow, so you don't need to nest the next `then`
.then((dataService) => dataService.getDocuments('MyCollection3'))
.then((docs) => {
// keep a reference to the element instead of searching for it in each loop.
console.log(docs)
tempi = 0;
for (const doc of docs) {
dataObj[tempi] = {
name: doc.name,
projected: doc.projected,
actual: doc.actual,
le: doc.le,
}
tempi++;
}
console.log(dataObj)
});
var i = 0;
console.log('fin', dataObj)
The VSS.getService()
connects to a data storage provided by Microsoft's VSTS extension kit. I declare an empty array before the assignment and assign objects into the array inside my getService
.
I get docs
successfully, but when I print it out eventually it gives an empty array []
.
How can I make it persist?