I am trying to run several Sync-UDElement at the same time.
Each of them fetches some data from API (so they are slow). They all display one table from each API.
I run them all directly after each other:
I was hoping they would then all start loading at the same time, and load (one by one) when done.
This doesn’t seem to be case, it seems that as soon as the “next” Sync-UDElement is run, the previous one is cancelled.
Every click of the button generates different amount of data in the table, and more often than not, empty data.
Is this a bug of Sync-UDElement meant to work like this, or am I doing something wrong?
So, your example has multiple errors, not sure if they may be present in your production code…
First, do you mean Do you mean Sync-UDElement? Or did you create another function called Sync-UDDynamics?
Second, all the variables in your example are Dyn1Data instead of $Dyn1Data. Also they are all looking at the same data and trying to write to the same variable…
Sorry, i always mix up Sync-UDElement and Sync-UDDynamic.
The post was written just to display the issue, it is not the actual code.
I have corrected my post.
Same issue, they all load, but the result is random. Every button click gives back different data.
Only way i have gotten it to work so far is to do the Sync-UDElement one after each other, but this slows it down significally.
Instead of using New-UDTable -Data use… New-UDTable -LoadData. This makes the Table itself dynamic, and doesn’t rely on wrapping it in a New-UDDynamic.
Also some more information on what you are trying to accomplish will probably be helpful with figuring out options. Does the Data need to be refreshed on click, or is this a manual process because that’s what you know how to do? There is the option to use a UDEndpoint and updating a $Cache: scope variable, which all users would be able to use.
I’ll try to explain a little more, the biggest issue is that my code is much too big to post here (around 1000 lines).
I am trying to do a search page, for users in our AD. This information should then be displayed in 4 UDCards, one for each category of information, for example “Mail”, “General”.
I have created 4 functions, that are loaded in at the start of the dashboard, to check and manipulate the data, and return a table with this information.
I then run the Sync-UDElement, one for each of the UDCards, where the functions are called with a variable that has the user information stored.
Running all the Sync-UDElement at the same time (as my example) gives completely random output. Different tables are display, with different data each time I press the button.
The only solution i have found so far is that they call the next one when done:
Okay, first try putting the variables in the $Session: scope.
Now, some more questions.
You say you are displaying AD information separated out into cards… Where do the long running API calls come in?
Does data get manipulated on this page and actually changed in AD/any other system?
Can you provide a screenshot of the dashboard?
My current feelings on this is you may have some unneeded complexity in the script as well. I’m not sure if there are limits on posting code (long code blocks go into a scroll window). But having that will be useful as well.
Basically I do the same but I use a UDSelect with ONChange which syncronizes several UDDyns. But I use as already mentioned for the data a variable $session:DashData = @{} with $session:DashData.Api1 or $session:DashData.Api2 or $session:DashData.somethink. All UDDyns sync more or less at the same time without any data missing or anything wrong.
Sometimes the data is already updated in the UDSelect via the API and sometimes the Update happens in the UDDyn area. Which sometimes, according to my observation, makes a difference the first time visit the site.