0

I call SharePointPlus get list method to query SP list several times but I need some more data beside query result set inside triggered function of this method. Is it possible to pass variable (but variable1 inside funtion1, variable2 inside function2 ...) or get access to query body (where clause) inside function (I use parameter in the query which I need inside function)? Thanks in advance.

Edit:

Here is my code. I'd like to pass myArray_items[y-1][0] to every query function or get access to query body inside this function.

function queryListItems3() {  
  var myArray_items    = [];
  var myTable ="";
  var myArray    = [];
  var yy = 0;
  var y = 0;
  var ctx = SP.ClientContext.get_current();
  var items = SP.ListOperation.Selection.getSelectedItems(ctx);
  items.forEach(function(item){
     var i = 0;
     var listItem = WPQ3ListData.Row.filter(function(row){
       return row.ID == item.id;
     })[0];
     myArray_items[y] = [];
     myArray_items[y][i] = listItem.DET_Att12;
     i=i+1;
     myArray_items[y][i] = listItem.DET_Att2;
     i=i+1;
     myArray_items[y][i] = listItem.DET_Att3;           
     i=i+1;
     y=y+1;   
     $SP().list('Pracownicy').get({
        fields:"KontoAD,Dzia_x0142_",
        where:'Dost_x0119_py LIKE "' + myArray_items[y-1][0] + '"'        
        }).then(function(data,i) {
             myTable+= "<table id=tablica" + myArray_items[y-1][0] + "><caption style = 'text-align: left;'>ID  zasobu: " + myArray_items[y-1][0] +"</caption><tr><td>L.p.</td>";   
             for (var ik=data.length; ik--;) {
               var ii = 0;
               myArray[yy] = [];
               myArray[yy][ii] = data[ik].getAttribute('Dzia_x0142_');
               myTable+="<td style='width: 200px; text-align: center; font-size:12px;'>" + myArray[yy][ii] + "</td></tr>";  
               ii=ii+1;
               yy = yy +1;                       
             }
             yy=0;
             myTable+="</table>"; 
             localStorage.setItem("array", myTable);
             displayDiv.innerHTML = localStorage.getItem("array"); 
           });          
  }); }
  • 1
    Please provide your code... – AymKdn Mar 17 '18 at 11:18
  • Code provided under Edit – Marek Lopi Mar 17 '18 at 19:29
0

Your problem is not with SharepointPlus but the way you use Promises. You should use PromiseChain described here.

Then your code:

function PromiseChain(arr, fct) {
  var dfd = Promise.resolve();
  var res = arr.map(function(item) {
    dfd = dfd.then(function() {
      return fct(item)
    });
    return dfd
  });
  return Promise.all(res)
}

function queryListItems3() {  
  var myArray_items    = [];
  var myTable ="";
  var myArray    = [];
  var yy = 0;
  var y = 0;
  var ctx = SP.ClientContext.get_current();
  var items = SP.ListOperation.Selection.getSelectedItems(ctx);
  items.forEach(function(item){
    var i = 0;
    var listItem = WPQ3ListData.Row.filter(function(row){
      return row.ID == item.id;
    })[0];
    myArray_items[y] = [];
    myArray_items[y][i] = listItem.DET_Att12;
    i=i+1;
    myArray_items[y][i] = listItem.DET_Att2;
    i=i+1;
    myArray_items[y][i] = listItem.DET_Att3;           
    i=i+1;
    y=y+1; 
  });
  PromiseChain(myArray_items, function(item) {
     return $SP().list('Pracownicy').get({
        fields:"KontoAD,Dzia_x0142_",
        where:'Dost_x0119_py LIKE "' + item[0] + '"'        
      })
  })
  .then(function(data) {
     // "data" should be an array of results from the 'get' that you can use to build your HTML table code 
  });
} 

Note: I'm currently replying from my mobile phone because I'm on vacation on the other side of world

|improve this answer|||||
  • Thanks a lot. It works perfectly :) Have a nice vacation – Marek Lopi Mar 19 '18 at 13:05

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.