Description
This function counts histories on the database. The histories that are counted can be selected by a filter, combination of filters, or "buckets". Buckets are used to define date ranges, and a count of histories in each range is returned. Results can also be grouped by label.
Parameters
Name | Type | Description | |
---|---|---|---|
datasource | String, optional | The name of the datasource from where histories will be retrieved. This parameter overrides the same parameter in the worker configuration which in turn overrides the default datasource | |
buckets | Object, optional | Define a set of date ranges and count the histories in each range by created or last updated. If the count is zero nothing is returned (ie there isn't an empty bucket in the results). | |
buckets.key | String, required | Either | |
buckets.ranges[n].name | String, required | A name for the bucket, returned with the results | |
buckets.ranges[n].from | Integer, required | The beginning of the range (inclusive) measured in ms since the epoch | |
buckets.ranges[n].to | Integer, required | The end of the range (exclusive) measured in ms since the epoch | |
filter | Filter-object, optional | The filter specifies which histories will be counted. The syntax of filter objects relates to many methods and is explained in Filter Objects | |
filters | Array, optional | The filters array contains filter-objects and specifies multiple groups of histories to count | |
getsql | Boolean, optional | If true the return structure will include an element called "sql" which contains the query and the parameters which were used to retrieve the history data from the database. This option returns a large amount of data and is intended for testing and debugging This parameter cannot be used with the filters parameter - it only works when counting all histories or when using a single filter | |
groupby | String or array of strings, optional | A single history label ( | |
sealed | Boolean, optional | If sealed is true, then only histories that have been switched into read-only mode will be searched. If sealed is false then only writable histories will be searched. If sealed is not supplied, then all histories will be searched |
Returns
If no parameters, or the
If the
If the
If the
Examples
Count with Filters
This first example counts two types of history.
function(params, credentials) {
let resp = this.callWorkerMethod("history", "countHistories", {
"filters": [{
"key": "labela",
"EQ": "Feedback Review"
}, {
"key": "labela",
"EQ": "My History"
}]
});
return resp;
}
{
"id": 145,
"result": [6, 0],
"jsonrpc": "2.0"
}
Group Results from a Single Filter
This example counts histories created between December 2018 and December 2019 and groups the results by their
function(params, credentials) {
let resp = this.callWorkerMethod("history", "countHistories", {
"filter": {
"AND": [{
"key": "created",
"GT": 1544616000000
}, {
"key": "created",
"LT": 1576152000000
}]
},
"groupby": ["labela"]
});
return resp;
}
{
"id": 149,
"result": [{
"count": 4,
"labela": "File References"
}, {
"count": 3,
"labela": "Form submitted"
}, {
"count": 3,
"labela": "LiveChat"
}, {
"count": 4,
"labela": "Object Export"
}, {
"count": 124,
"labela": "Workflow"
}],
"jsonrpc": "2.0"
}
Count Histories Created Each Month Using Buckets
This example still looks for histories created between December 2018 and December 2019 but also uses buckets. Only histories that fit into the defined buckets are counted, those created in the other months of the year are ignored.
function(params, credentials) {
let resp = this.callWorkerMethod("history", "countHistories", {
"filter": {
"AND": [{
"key": "created",
"GT": 1544616000000
}, {
"key": "created",
"LT": 1576152000000
}]
},
"buckets": {
"key": "created",
"ranges": [
{"name": "jul", "from":1561939200000, "to":1564617600000},
{"name": "aug", "from":1564617600000, "to":1567296000000},
{"name": "sep", "from":1567296000000, "to":1569888000000}
]
}
});
return resp;
}
{
"id": 153,
"result": [{
"bucket": "jul",
"count": 31
}, {
"bucket": "aug",
"count": 31
}, {
"bucket": "sep",
"count": 31
}],
"jsonrpc": "2.0"
}
Combine Buckets and Groups
Finally, you can use buckets and groupby in combination. Histories are grouped by label within their date ranges.
function(params, credentials) {
let resp = this.callWorkerMethod("history", "countHistories", {
"filter": {
"AND": [{
"key": "created",
"GT": 1561939200000
}, {
"key": "created",
"LT": 1576152000000
}]
},
"buckets": {
"key": "lastupdated",
"ranges": [
{"name": "jul", "from":1561939200000, "to":1564617600000},
{"name": "aug", "from":1564617600000, "to":1567296000000},
{"name": "sep", "from":1567296000000, "to":1569888000000}
]
},
"groupby": "labela"
});
return resp;
}
{
"id": 157,
"result": [{
"bucket": "jul",
"count": 31,
"labela": "Workflow"
}, {
"bucket": "aug",
"count": 31,
"labela": "Workflow"
}, {
"bucket": "sep",
"count": 1,
"labela": "File References"
}, {
"bucket": "sep",
"count": 30,
"labela": "Workflow"
}],
"jsonrpc": "2.0"
}