If you have a comment on this topic, contact Aptify Documentation. If you want to return to the Aptify Community Site, please click here.

Get Data From a View (via JavaScript API)

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

  1. Know the Name of the View you want.

    var randomPersonsViewName = "25 Random People";
  2. 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.

    var personsEntityName = "Persons";
  3. 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.

    Prompt Data
    // 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.

    Single Prompt Data
    var personsPromptData = "Baldwin"; 
  4. If you want to filter the View, construct a filter. This will be added to the WHERE clause of the View.

    Filter
    // We might want to see random people in only a certain range of IDs
    var personsFilter = "ID < 100 OR ID > 4000"; 
  5. 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.

    First 1000 Rows
    var topCount = 1000; 
    Rows 200-400
    var skipCount = 200; // determines the starting row
    var topCount = 400;  // determines the final row

    topCount is the maximum row number, not the maximum number of rows.

    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.

  6. 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

    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 + ".");
    	}
    }; 
  7. 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.

    Calling Aptify.framework.views.utility.getViewData()
    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
    });

Copyright © 2014-2019 Aptify - Confidential and Proprietary