My query.data is never the same on multiple trigger

Hi

here is my query triggered by a button

js_categories.trigger();
js_Columns.trigger();
js_Entities.trigger();

var CurrentYear_data;


query_eurex_conso.trigger( {
      additionalScope: { 
        theCategories:js_categories.data,
        theColumns:js_Columns.data,
        theEntities:js_Entities.data,
        theYear: year.value},
      onSuccess: function(data) {
        return data;
        },
      onFailure: function(error){
      console.log(error);
      }
    });
 CurrentYear_data=Object.assign({}, query_eurex_conso.data); 

query_eurex_conso.trigger({
      additionalScope: { 
        theCategories:js_categories.data,
        theColumns:js_Columns.data,
        theEntities:js_Entities.data,
        theYear: (year.value-1)},
      onSuccess: function(data) {
        state_LastYearData.setValue( data);
        //return data;
        },
      onFailure: function(error){
      console.log(error);
      }
    });


return CurrentYear_data;

Basically I launched twice the same query. First for the current year, then for the last year.
I want to display the of current year in a table and store the the data of last year in a temporary state.

if I launch multiple time that piece of code, my table displays the data of, either the current year or the last year !

What do I miss ?

thank in advance for your help.

I figured out that my queries were asynchronous and rewrote the whole code.
Thanks for your helps :wink:

async function asyncCall() {
  
  let cat= await js_categories.trigger();
  let col= await js_Columns.trigger();
  let ent=  await js_Entities.trigger();
  
  let data1 = await query_eurex_conso.trigger( {
      additionalScope: { 
        theCategories:cat,
        theColumns:col,
        theEntities:ent,
        theYear: year.value}});
  
  let currentYearData=Object.assign({}, data1); 
  
  let data2 = await query_eurex_conso.trigger( {
      additionalScope: { 
        theCategories:cat,
        theColumns:col,
        theEntities:ent,
        theYear: (year.value-1)}});
  
  state_LastYearData.setValue(data2);
  
  return currentYearData;}

return asyncCall();
1 Like