• <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.countCases Action

Format
i = CS.Data.countCases(dataId := ...,
                   
ʃ, status := ...ʅ
                   
ʃ, filter := ...ʅ)
ArgumentDescriptionTypes / Required
dataIdThe resource ID returned by Data.open, or a dictionary name.number, string
recommended
statusOptions for the status of the cases to query.
The default value is "notDeletedOnly".
string
not required
filterOptions for how the queried data should be filtered.object
not required
Description
The Data.countCases action returns the number of cases that exist in a data source. This value is also retrievable using Data.query.
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 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.
This action is similar to the CSPro logic function countcases.
Return Value
The action returns the numbers of cases that match the filters.
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 */;

// count the number of non-deleted partial cases
CS.Data.countCases({
    dataId: dataId,
    status: 
"partialsOnly"
});

// count the number of non-deleted cases with a key starting with "01"
CS.Data.countCases({
    dataId: dataId,
    filter: {
        operator: 
"startswith",
        value: 
"01"
    }
});

// count the number of cases, including deleted cases, with a key >= "01"
CS.Data.countCases({
    dataId: dataId,
    status: 
"all",
    filter: {
        operator: 
">=",
        value: 
"01"
    }
});
See also: Data Action Invoker Namespace, Data.contains Action, Data.query, CountCases Function