I work on a script to recover information in a list and create a pdf with it. To create my PDF I use makePDF and JSOM to recover the information. I've already created my pdf and recover my data, but my function doesn't work with many list's items.
var id;
function pdfCtrl($scope){
$scope.form = { id:0};
var allItems;
var listeDef = new Array();
onQueryFailed = function(sender, args) {
console.log('Request failed ' + args.get_message());
}
$scope.downloadPdf = function($event){
var x = $scope.form;
$event.preventDefault();
var clientContext = SP.ClientContext.get_current();
var web = clientContext.get_web();
var list = web.get_lists().getByTitle("Congés");
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
clientContext.load(allItems);
id = x.id;
clientContext.executeQueryAsync(
Function.createDelegate(this, onQuerySucceededDown2),
Function.createDelegate(this, onQueryFailed)
);
};
onQuerySucceededDown = function(){
var listEnumerator = allItems.getEnumerator();
while (listEnumerator.moveNext()){
var currentItem = listEnumerator.get_current();
if (currentItem.get_id() == id){
pdfMake.createPdf(genratepdfDefinition(currentItem)).download('optionalName.pdf'); }
//else if (id == 0){
//pdfMake.createPdf(genratepdfDefinition(currentItem)).print();
//pdfMake.createPdf(definition).download();
// }
else {
}
}
}
}
I search the problem and I found the function always use the same "current item". So I want to wait for the end of the creation of my pdf and after that create the next. If somebody can help me, I will love him! Thanks!