locked
HTML Client entity query return _SingleOrDefault() will not bind. RRS feed

  • Question

  • In the Lightswitch HTML client, in the server project, I have created a query on an entity, added a single filter bound to a parameter.

    But I want to return a single record, not an entity set. A preprocess query apparently can't define the output, even if you query a _SingleorDefault() result.

    There is a setting for this in the query designer:

    Now it misbehaves....

    After the query is added to the screen designer, I bind the parameter to a local screen property (set to required parm value) which is set to (in this case) a string value.

    When run....nothing is returned.

    Everything is set correctly. The bound parm value even shows on the screen property. I know it is set right.

    But in my diagnosis I put a string literal value in the screen parameter binding field....and the query works?!?.

    So why will it not take a screen string property???

    I also tried to set the entity via js in various ways:

    • Setting a single value on the entity
    • querying via myapp.activeDataWorkspace... filtered query and then setting the entity to the result
    • binding in the screen created method

    Nothing seems to work and I've been trying at this for over a while now.

    Obviously there is no further support from MS, but is this a design flaw or are my approaches flawed?

    Any similar experiences?

    Thanks!



    • Edited by FaithNoMore Friday, October 27, 2017 4:49 AM typo
    Friday, October 27, 2017 4:47 AM

All replies

  • Hi faithNoMore,

    I didn't find any document about this issue, maybe you could start a support case for further help.

    Best Regards,

    Yuk Ding

    Monday, October 30, 2017 3:18 AM
  • Ok, I have kind of solved it, I basically identified the cause, and how it must be used.

    In order to query a single or default, it has to be passed as a screen parameter before the screen render event. ie. from the calling code or beforeShown options.

    You cannot add the parameter value anytime after the screen created event.

    Even calling the screen.getEntity() by either adding the param value in the call 'screen.getEntity(myParmValue)' or the 'myapp.BrowseEntity(myParmValue)'


    I also reviewed the msls-2.5.3.js file and it would be extensive to modify.
    • Edited by FaithNoMore Tuesday, October 31, 2017 2:31 AM
    Tuesday, October 31, 2017 2:29 AM
  • Hi FaithNoMore,

    Thanks for sharing your experience.

    Best Regards,

    Yuk Ding

    Tuesday, October 31, 2017 7:43 AM
  • Not sure if this helps, but I also had headaches trying to pull 1 value from a query and display it on a screen, or just use the value in code somewhere. I gave up on the built in GUI solutions, and found better results using queries written in the _postRender code.

    Example, I needed to lookup the currently logged in user (from the server) and pull a User Name that I had in a table. So I would get something like "ABC\EMP001" back from the server, and feed that into the filter of my query to pull the users full name from a SQL table.

    I first added a view that returned the two columns UserID and UserFullName.Then a Local Property, String type, not required, and added it to my screen. Then added a _postRender code stub.

    Within the postRender code:

    myapp.BrowsevwData.pCurrentUserName_postRender = function (element, contentItem) {

        msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {

            var filter = "(UserID eq '" + PromiseResult + "')";

            myapp.activeDataWorkspace.AppData.vw_UserNameLookup.filter(filter)

            .execute().then(function (result) {

                contentItem.value = result.results[0].FullName.toString();

            });

        });

    };

    function CallGetUserName(operation) {

        $.ajax({

            type: 'post',

            data: {},

            url: '../GetUserName.ashx',

            success: operation.code(function AjaxSuccess(AjaxResult) {

                operation.complete(AjaxResult);

            })

        });

    }

    You probably don't need all of the CallGetUserName stuff, really you just need the section inside of the promiseOperation. And also if you need to feed something from the screen into the filter, you use the contentItem to grab it. Remember the data types, if the filter is string keep the single quotes, if number drop them:

    var filter = "(UserID eq '" + contentItem.screen.ID + "')";

            myapp.activeDataWorkspace.AppData.vw_UserNameLookup.filter(filter)

            .execute().then(function (result) {

                contentItem.value = result.results[0].FullName.toString();

            });

    Hope that helps.


    Jeremy

    Wednesday, November 1, 2017 4:32 PM