When there is a View defined with all the data you need, you can simply get the data from that View rather than pulling it from many GE Objects.
Step-by-step guide
Know the Name of the View you want.
Code Block language js linenumbers true var randomPersonsViewName = "25 Random People";
Know the Entity on which the View is defined; this disambiguates Views that have the same name but are defined on different Entities, such as "All" Views.
Code Block language js linenumbers true var personsEntityName = "Persons";
If your View is a prompted View, construct your prompt data. (Our example View is not prompted.) Just as when configuring a Form Template Part or Dashboard Part using a View in Aptify, prompt data is pipe-separated.
Code Block language js title Prompt Data linenumbers true // Prompt data for a prompted View of Persons that prompts for LastName and FirstName // would look like this if we wanted Aiesha Baldwin to be in the View: var personsPromptData = "LastName=Baldwin|FirstName=Aiesha";
A view with only one promptData field should just pass the value of that field, not the name.Code Block language js title Single Prompt Data linenumbers true var personsPromptData = "Baldwin";
If you want to filter the View, construct a filter. This will be added to the WHERE clause of the View.
Code Block language js title Filter linenumbers true // We might want to see random people in only a certain range of IDs var personsFilter = "ID < 100 OR ID > 4000";
By default, you will get the first 500 rows in the View. If you want a different set of rows, you should set up top and skip variables.
Code Block language js title First 1000 Rows linenumbers true var topCount = 1000;
Code Block language js title Rows 200-400 linenumbers true var skipCount = 200; // determines the starting row var topCount = 400; // determines the final row
Tip topCount is the maximum row number, not the maximum number of rows.
Code Block language js linenumbers true var skipCount = 500;
Since topCount defaults to 500, setting skipCount to 500 will return no rows: it returns rows 500 + 1 through 500, not rows 500 + 1 through 500 + 500.
Define a callback function to act on the View data that is retrieved. Getting View data involves a trip to the server, so it is asynchronous
Code Block language js linenumbers true var personsViewCallback = function (result) { if (results.success) { var viewData = result.data.result; // viewData is an array of rows // Each row is an object with the column values keyed by column name properties var firstRandomPersonID = {}; if (viewData.length > 0) { firstRandomPersonID = viewData[0].ID; } } else { Aptify.framework.exceptionManager.publish("Error: View failure with server error code " + result.servererrorcode + "."); } };
Finally, call Aptify.framework.views.utility.getViewData(), passing the options you defined. Of course, all of these could be defined inline at this point instead of pre-defining them as in this example.
Code Block language js title Calling Aptify.framework.views.utility.getViewData() linenumbers true Aptify.framework.utility.getViewData({ viewName: randomPersonsViewName, viewEntityName: personsEntityName, // This View is not prompted, so we won't add a promptData property to the options we're passing filter: personsFilter, // This View is already limited to 25 people, so we won't add topCount or skipCount to the options we're passing callBack: personsViewCallback });
...
Related articles
Filter by label (Content by label) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|