locked
Custom query with WHERE from HTML client promise query RRS feed

  • Question

  • Hi all.

    I need to dynamically set a list selected item based on a custom query but I need a where clause to find only a single record on the entity.

    It should be pretty similar to below but am not sure where/how I add a filter or where clause to this. I'm very familiar with doing this at the data layer with pre-process or filters. However, not sure how to code that dynamically?

    myapp.activeDataWorkspace.ApplicationData.OrdersForUser().execute().then(function (results) {

            var TotalCountOfOrders = CountOrders(results);
    
            screen.TotalOrdersForCurrentUser = TotalCountOfOrders.toString();
    

    });

    Can someone please post a specific example or sample code if possible??

    Saturday, March 8, 2014 1:53 AM

Answers

  • Ok, got this all figured out, it was a simply case that I was trying to query against the direct entity. However, that does not work, you HAVE to create a query off the data entity and call the promise on that.

    Once that is in place everything works great and I'm able to use filters, call promise, loop, etc. :)

    myapp.activeDataWorkspace.ApplicationData.MyCustomQuery().filter("Custom Filter Here").execute().then(...function goes here

    • Marked as answer by Angie Xu Monday, March 10, 2014 6:49 AM
    Monday, March 10, 2014 2:47 AM

All replies

  • Thought I might have had this but my code is returning null errors on both the methods below. Not sure what is wrong and have seen this code on multiple examples?!?!!

    I'm working from examples here: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/1207/HUY-Volume-III-ndash-Popups-Dirty-Visual-Collections-and-Using-Prototypes-To-Calculate-Child-Collections.aspx

        // Query the database
        myapp.activeDataWorkspace.SPPurchaseReqData.GLCodes.execute.then(function (results) {
            var glCodeList = results;
        });

    // Check to see if this is a duplicate -- construct a query
        var filter = "(GLCode1 eq " + msls._toODataString(screen.Item1.GLCode, ":String") + ")";
        myapp.activeDataWorkspace.SPPurchaseReqData
            .GLCodes
            .filter(null)
            .execute()
            .then(function (result) {
            // Get the results of the query
            var selectedGlCode = result.results[0];

            screen.QueryGLCodeByItemSelection.selectedItem = selectedGlCode;
        }, function (error) {
            alert(error);
        });

    Saturday, March 8, 2014 5:34 AM
  • One additional note, I am using SharePoint as the data source, no databases are involved
    Saturday, March 8, 2014 6:32 AM
  • Ok, got this all figured out, it was a simply case that I was trying to query against the direct entity. However, that does not work, you HAVE to create a query off the data entity and call the promise on that.

    Once that is in place everything works great and I'm able to use filters, call promise, loop, etc. :)

    myapp.activeDataWorkspace.ApplicationData.MyCustomQuery().filter("Custom Filter Here").execute().then(...function goes here

    • Marked as answer by Angie Xu Monday, March 10, 2014 6:49 AM
    Monday, March 10, 2014 2:47 AM
  • Hi Madd

    Glad that you've solved your problem by yourself and I come here to confirm and close the issue. If you have anything urgent, please feedback by creating another issue. :)

    Best regards

    Angie Xu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 10, 2014 6:49 AM