locked
Populate ChoiceList from Query at postRender - HTML Client RRS feed

  • Question

  • I have a screen with two tabs.  First tab contains search parameters.  Second tab contains the search results.

    I have an employee Parameter that I have been able to successfully populate from a table.  but I would now like the selections ordered by employee name.  My code is pasted below, you will see i have attempted to use the .orderby but doesnt seem to work.  I get the error shown below.  Anyone have any ideas?

        myapp.activeDataWorkspace.CrowleyData
            .Employees
            .orderBy("EmployeeName")
            .load()
            .then(function onComplete(data) {
                var values = [];
                data.results.forEach(function (item) {
                    values.push({
                        value: item.EmployeeName,
                        stringValue: item.EmployeeName
                    });
                });
                // replace dummy entry with entries loaded from database, auto select first entry
                // and call .dispatchChange() to ensure dropdown is rendered correctly
                contentItem.choiceList = values;
                contentItem.dispatchChange("choiceList");
                contentItem.value = values[0].value;
            }, function onError(error) {
                msls.showMessageBox(error, {
                    title: "Error loading Order Statuses from database"
                });
            });

    If i remove the orderby it works.

    Tuesday, June 10, 2014 7:13 PM

Answers

  • Hi Voyagr12, try this:

    myapp.activeDataWorkspace.CrowleyData
            .Employees
            .orderBy("EmployeeName")
            .execute()
            .done(function onComplete(data) {
                var values = [];
                data.results.forEach(function (item) {
                    values.push({
                        value: item.EmployeeName,
                        stringValue: item.EmployeeName
                    });
                });
                // replace dummy entry with entries loaded from database, auto select first entry
                // and call .dispatchChange() to ensure dropdown is rendered correctly
                contentItem.choiceList = values;
                contentItem.dispatchChange("choiceList");
                contentItem.value = values[0].value;
            }, function onError(error) {
                msls.showMessageBox(error, {
                    title: "Error loading Order Statuses from database"
                });
            });

    The error is when you are calling CrowleyData.Employees because you are using "OrderBy" that convert the call in a query because the ordenation need to be performed before collecting the VisualCollection. So then, "load" only apply if you are not querying the data, you need to use "execute()" instead. 
    Also I put in the code "done" replacing "then" that give better performance in my experience.

    • Proposed as answer by Angie Xu Friday, June 20, 2014 1:47 AM
    • Marked as answer by Angie Xu Monday, June 23, 2014 1:35 AM
    Tuesday, June 10, 2014 10:15 PM