• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • Synchronization
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security, Resource Management, and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
        • Data Action Invoker Namespace
        • Data.close Action
        • Data.contains Action
        • Data.countCases Action
        • Data.deleteCase Action
        • Data.getCurrentCase Action
        • Data.open Action
        • Data.query
        • Data.queryCases Action
        • Data.queryKeys Action
        • Data.readCase Action
        • Data.writeCase Action
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Network Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • Sync Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Data.query

s = CS.Data.query(dataId := ...,
                 
content := ...ʅ
               
ʃ, status := ...ʅ
               
ʃ, sort := ...ʅ
               
ʃ, filter := ...ʅ
               
ʃ, limit := ...ʅ
               
ʃ, offset := ...ʅ
               
ʃ, serializationOptions := ...ʅ)
ArgumentDescriptionTypes / Required
dataIdThe resource ID returned by Data.open, or a dictionary name.number, string
recommended
contentThe content to query.string
required
statusOptions for the status of the cases to query.
The default value is "notDeletedOnly".
string
not required
sortOptions for how the queried data should be sorted.object
not required
filterOptions for how the queried data should be filtered.object
not required
limitThe maximum number of results to return from the query.number
not required
offsetThe number of results to skip before starting to return results from the query.
The default value is 0.
number
not required
serializationOptionsOptions for how cases should be serialized.object
not required
Description
The Data.query action queries content from a data source. The options for queryable content include:
  • "count": Returns a count of cases. This value is also retrievable using Data.countCases.
  • "keys": Returns an array of strings containing the key of each case. This value is also retrievable using Data.queryKeys.
  • "summaries": Returns an array of objects containing the "summary" of each case. The summary includes the key, "position", deleted status, partial status, verified status, and the case note.
  • "cases": Returns an array of objects containing JSON representations of each case. The optional serializationOptions argument allows you to specify how the case should be serialized, potentially overriding the default application settings. This value is also retrievable using Data.queryCases.
The data source is identified using dataId. If specified as a string, it references the data source that is connected to a dictionary that is part of an application. If specified as a number, it is processed as a resource ID returned by Data.open. This typically references non-application data sources. While optional, this should generally be specified explicitly. (If there is only one data source open, the resource ID can be calculated implicitly.)
The string argument status can be used to filter cases by "status":
  • "all": Do not apply a filter, processing all cases, including deleted cases.
  • "notDeletedOnly": Process only non-deleted cases.
  • "partialsOnly": Process only non-deleted cases that are partially saved.
  • "duplicatesOnly": Process only non-deleted cases where there are at least two cases with the same key.
The argument sort, an object, can be used to modify the order of the query's results. The filters include two primary values: order and ascending:
OrderAscendingDescription
"key"trueResults are ordered by key in ascending order.
"key"falseResults are ordered by key in descending order.
"position"trueResults are ordered by "position" in ascending order.
"position"falseResults are ordered by "position" in descending order.
In other contexts, CSPro refers to key order as "indexed" and position order as "sequential." If not specified, results are ordered in ascending order.
The argument filter, an object, can be used to further filter cases. The filters include two primary values: operator and value:
OperatorDescription
"startswith"Only consider cases with a key starting with the specified value.
"<"Only consider cases with a key that is less than the specified value.
"<="Only consider cases with a key that is less than or equal to the specified value.
">="Only consider cases with a key that is greater than or equal to the specified value.
">"Only consider cases with a key that is greater than the specified value.
Alternatively, by defining type as "position", these checks (other than "startswith") will apply to the "position" of a case. The type is "key" by default.
By default, the action returns all results in the data source that match the query. This may be more information than necessary. When working with a large amount of data, you will want to query only a subset of the data using the limit and offset arguments. The limit sets the maximum number of results that the query should return. The offset specifies a certain number of results to skip before starting to return results. Together, these values can be used to incrementally process results. For example, a limit of 20 with an offset of 50 would return results ordered 51–70. The Data.queryCases documentation includes an example of using a limit to process cases in a loop.
Return Value
The action returns an array of keys, summaries, or cases, or a number with a count.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, or if:
  • The data source ID is not valid.
  • There is an error interacting with the data source.
Example (JavaScript)
const dataId = /* retrieved from a call to CS.Data.open */;

// query the summaries to get information about the
// last case in the data source (sorted by key)
const summaryQuery = CS.Data.query({
    dataId: dataId,
    content: 
"summaries",
    status: 
"all",
    sort: {
        order: 
"key",
        ascending: 
false
    },
    limit: 1
});

if (summaryQuery.length !== 0) {
   
const lastCaseSummary = summaryQuery[0];

    print(`Sorted by key, the last key is 
"${lastCaseSummary.key}" ` +
          `(located at position: ${lastCaseSummary.position}).`);
}
See also: Data Action Invoker Namespace, Data.countCases Action, Data.queryCases Action, Data.queryKeys Action, Data.readCase Action