Callback function not reachable when changing queryTemplate on CSWP

32 Views Asked by At

I'm working with Content Search Web Parts, I need to run code when the queryTemplate process is done. So, I'm sending the query through a function

function sendQuery(myQuery) {
  setQuery2(myQuery, function() {
      console.log('Process done for setQuery2');
      window.open('Customer.aspx', '_blank');
      console.log('Process done');
  });
}

function setQuery2( query, callbackFunction ) {
  var ctrlA = $getClientControl( $("#containerDivA")[0] );
  var ctrlB = $getClientControl( $("#containerDivB")[0] );
  console.log('Set query');
  var q = query;
  q += ' proOrd:CurrR';

  ctrlA.get_dataProvider().set_queryTemplate(q);
  console.log('Running new query in A');
  ctrlA.get_dataProvider().issueQuery();

  ctrlB.get_dataProvider().set_queryTemplate(q);
  console.log('Running new query in B');
  ctrlB.get_dataProvider().issueQuery(); 
}

The expectation is to run the window.open when the setQuery2 has finished the process of querying the service but it is not working, is something wrong on it? Thanks for your help.

1

There are 1 best solutions below

0
On

I just realized, the call to callbackFunction were removed that's why is not reaching the code.

Just make the call to callbackFunction() after the process. If any additional comment please go ahead.