When I populate a list in uiDesigner 1 value updates all values (EDITED)

Hello,

I'm trying to populate a list of users with their roles, this is the code:

 

$data.user = 0;

$data.listaTratada=[];

$data.grupo = "";

for( var i = 0; $data.listaUsuariosTotal.length >= i; i++){

    $data.apiGetRoles = "../API/identity/membership?p=0&c=10&f=user_id="+$data.listaUsuariosTotal[i].id+"&d=role_id";


         $data.listaTratada.unshift({"grupo":$data.RolesPorUsuario[0].role_id.name,
        
         "usuario":$data.listaUsuariosTotal[i].firstname,
        
         "id":$data.listaUsuariosTotal[i].id});

$data.listaTratada=[];

}

 

when launching this code, "grupo" changes to the same value on every element on the table, "grupo" is obtained from an api call, saved on the "RolesPorUsuario" variable, is there a reason why it does this and if there a fix?

 

 

EDIT : turns out the api call where I get "grupo" doesn't update fast enough, is there any way to guarantee the api call has been made properly?

"grupo" variable takes the value of the last user of listaUsuariosTotal, isn it??

It could be about the order of execution of the task. I suppose that the  External APis execute in the end, and change all the values with the last value of listaUsuariosTotal.

hello,
that's correct, how could I make it so the api gets called as I call it? or how can I summon the api whenever I need it