question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropdown on a Dialog, data coming from LookupScript/LookupEditor; not updating until recompiling and re-publishing of project

See original GitHub issue

Hi JaiQ,

John Ranger here again 😃

We are now in Pilot with my Clientmanagement app and most things run fine.

Today I had a strange phenomen for which I ask you for more insight how the things behind the Scene are working within Serenity (I have read the part with the lookupScript/LookupEditor but still don’t get the “behind the scene”).

Environment:

  • Serenity 1.9.9-based app.
  • 1 Webserver (Windows Server 2012 (R1)
  • IISApplication Pool timed-auto-Recycling deactivated (so that the app anytime loads fast)

What happened?

I have a table called ADUsers which is filled by a Sync-Powershell-Script which polls the “ADUsers” from SCSM (about 1350 users). By an Event which I still have to investigate, the Users were inserted twice so for each natural user, I had two entries within the table.

Within the serenity-based app, This Table data (part of, not all fields) is "published to the Client side via the [LookupScript] entry within the xyzRow.cs file.

In the Dropdown of a Dialog, this Lookup-Script is consumed by a Dropdown field with a [LookupEditor] entry in xyzForm.cs.

Now… the double entries were visible within the Dropdown (which actually has alerted me that something with the sync must be wrong).

I then cleaned up the ADUsers table (within MS SQL database) so that there was again only 1 row per natural user.

For the reference if someone else has the Problem of removing duplicates and Keep the 1st entry of each in the DB (do this in SQL Management Studio --> New query):

use <your database> 
go
delete [dbo].[<your table>]
from (
    select t.<ID field name> from  [dbo].[<your table>] t
    where exists(
          Select t2.<ID field name> from [dbo].[<your table>] t2
          where t.<field with double content e.g. a name field>=t2.<field with double content e.g. a name field> and
               t.<ID field name> > t2.<ID field name>
       )
    ) as x
where x.<ID field name>=[dbo].[<your table>].<ID field name>

I then closed and reopened Internet Explorer and opened the same Dropdown. --> There were still two entries for each natural user. --> An IE-Cache-delete didn’t help at all.

After that, I used Chrome which I never had used before on this Client and again, the same Dropdown was filled with two entries per natural user so the unexpected data must be coming from the server.

I could by no means refresh this data except by Clean–>rebuild the whole Project and re-publishing it.

As I don’t fully understand, at which Points-in-time / Events the lookup script is generated/refreshed (I expected that this is dynamically created everytime a browser opens the serenity-based app and then Downloads it to the Client for further use in lookupEditors), I ask you to explain how the end-to-end (Database->to->Dropdown-field-in-dialog) data provisioning works, where it is cached (Server and client-side), etc.

Questions:

  1. Is there a possibility to define the server-side lifetime of such a lookup script/data in it?
  2. Is there a possibility to define the client-side lifetime of such a lookup script/data in it?
  3. Is there an easy replacement within the serenity framework for “just-in-time” client-side-to-Webservice-Data-Lookup?

Thanks again for your insight

and with Kind regards,

John

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JohnRangercommented, Mar 22, 2016

Hi all,

as promised, here the code for the Cach invalidate on Server side.

Create an MVC Controller with the following code inside:

using Serenity;
using System.Web.Mvc;

namespace ClientAndAssetManagement.Modules.Common.Control
{

    [RoutePrefix("Control"), Route("{action=index}")]
    public class ControlController : Controller
    {


        // GET: Control/InvalidateCache
        public ActionResult InvalidateCache()
        {

            var ReturnResult = "ok";

            try {
                LocalCache.RemoveAll();
            }
            catch
            {
                ReturnResult = "not ok";
            }
            return Json (new { result = ReturnResult }, JsonRequestBehavior.AllowGet);
        }


    }
}

and call it from where you Need to invalidate the Cache like this:

http://your serenity app/Control/InvalidateCache

As a result you will get a json Feedback with either { result: “ok”} or { result: “not ok”}

Bonus: From within Powershell, call it like this:

$result= Invoke-RestMethod -uri "http://your serenity Webpage/control/invalidatecache"

Hope this helps someone.

With Kind regards,

John

1reaction
volkanceylancommented, Feb 17, 2016

About dynamic script lifetime

  • DynamicScriptManager has a registry of all dynamic scripts, including lookups
  • When page is loaded a special dynamic script with list of all registered scripts (RegisteredScripts.js) and their current hash values are sent to script side.
  • If a dynamic script, for example Northwind.Customer is not requested before by this or another user, its data and hash is not available yet at server side, so a timestamp value is used instead of actual hash (Otherwise, i would have to load data for 1000s of tables to generate RegisteredScript.js if you had a 1000s of lookup script definitions. First user would have to wait so long.)
  • When a lookup editor tries to populate its items, it asks for lookup data with Q.GetLookup(“SomeLookupKey”) at script side
  • If this lookup data is not loaded to current page by script (in memory) yet, it needs to be loaded from server side
  • Before trying load from server side, Q.GetLookup checks if registered scripts list has such a script and what is its hash. If no such script, you’ll get an error
  • It tries to load that script with its URL and hash, so that script side will not use a browser cached script if something changed server side
  • Then through DynJS.axd dynamic script manager kicks in server side.
  • Script manager checks if this script is initialized (loaded from DB etc) before, if not it loads by calling producer function.
  • If it was already initialized, and not expired (time based expiration) cached version is sent back.
  • If expired, again call producer function.
  • DynJS.axd sends back dynamic script to client side
  • Client side runs script and caches results in browser memory

I’ll probably add a flowchart to Serenity Guide 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

State of the dialog not updating on dropdown change
1 Answer. Because the dialog and bottom sheets don't have states so you must create a different stateful widget for the widget you...
Read more >
Drop-down list not updating from source list
I have a list of date which is the source for my validation, this list is an excel table, when I add a...
Read more >
[BUG] dcc.Dropdown value does not update when selected ...
Dropdown are updated to remove a currently selected option, the UI updates to remove that value, but the value parameter does not update....
Read more >
DropDown not updating - Power Platform Community - Microsoft
I have a Drop Down in a data card in my Edit form with the first value being "SELECT". I have to change...
Read more >
dropdown list-dynamically update while dialog is running?
Hi everyone, I am a newbie with Labview, and am having trouble coming up with a solution to the following problem. I have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found