> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# StatLib

> Class for using the Service statistics library.

Class for using the Service statistics library.

## Constructors

### StatLib()

```crmscript theme={null}
StatLib
```

Initializes a new instance of the StatLib class.

## Methods

## addAggregate(Integer,Integer,String,String,Integer)

Adds an aggregate function to the specified group

An aggregate function is a function that is calculated for all values for a given column in a group. For example, the average response time for each category.

```crmscript theme={null}
Void addAggregateStatLib.addAggregate(Integer groupColumn, Integer column, String name, String type, Integer decimals, Integer uniqueColumn)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Available functions:

  * Count
  * Sum
  * Avg
  * Max
  * Min
</Note>

## addAggregate(Integer,Integer,String,String,Integer,Integer)

Adds an aggregate function to the specified group

An aggregate function is a function that is calculated for all values for a given column in a group. For example, the average response time for each category.

```crmscript theme={null}
Void addAggregateStatLib.addAggregate(Integer groupColumn, Integer column, String name, String type, Integer decimals, Integer uniqueColumn)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Available functions:

  * Count
  * Sum
  * Avg
  * Max
  * Min
</Note>

## addCallback(Integer,String)

Adds a callback. A callback is a PARSER-snippet that will be executed for the given column for each row.

```crmscript theme={null}
Void addCallback(Integer column, String script)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  This is an old method. Use StatResult and iterate instead.
</Note>

## addGroup(Integer,Bool)

Adds a group to the StatLib instance. A group is a subset of the results that have a common value for a given column. Aggregate values can be calculated for groups, for example, the average response time per category.

```crmscript theme={null}
Void addGroup(Integer column, Bool desc)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## addGroup(Integer,Bool,Bool)

Adds a group to the StatLib instance. A group is a subset of the results that have a common value for a given column. Aggregate values can be calculated for groups, for example, the average response time per category.

```crmscript theme={null}
Void addGroup(Integer column, Bool desc, Bool compareAsNumber)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## dropOrder()

Calling this function will make the StatLib instance skip sorting the results in the groups.

```crmscript theme={null}
Void dropOrder()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## execute(Parser)

Runs the query and aggregations and stores the results in a Parser

```crmscript theme={null}
Void execute(Parser parser)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can choose between storing in a Parser or a StatResult by passing the appropriate object.
</Note>

## execute(StatResult)

Runs the query and aggregations and stores the results in a StatResult

```crmscript theme={null}
Void execute(StatResult result)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can choose between storing in a Parser or a StatResult by passing the appropriate object.
</Note>

## setGenericSearch()

Use the given GenericSearch entry as query (instead of SQL string).

```crmscript theme={null}
Void setGenericSearch(GenericSearch gs)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setName(String)

Sets the name for the instance. The name is used to prefix the result in the Parser.

```crmscript theme={null}
Void setName(String name)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setSearchEngine()

Use the given SearchEngine entry as query (instead of SQL string).

```crmscript theme={null}
Void setSearchEngine(SearchEngine se)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setSql(String)

Sets the query for the instance. **This method is not available in CRM Online.**

```crmscript theme={null}
Void setSql(String sqlStatement)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## setStringMatrix()

Use the given StringMatrix entry as query (instead of SQL string).

```crmscript theme={null}
Void setStringMatrix(StringMatrix sm)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)


## Related topics

- [Using StatLib class in CRMScript for reporting](/en/automation/crmscript/tutorials/using-crmscript-statlib-for-reporting.md)
- [StatResult](/en/automation/crmscript/reference/CRMScript.Native.StatResult.md)
- [Namespace CRMScript.Native](/en/automation/crmscript/reference/CRMScript.Native.md)
- [CRMScript Reference](/en/automation/crmscript/reference/index.md)
- [Document library](/en/document/library/learn/index.md)
- [Permissions for SuperOffice Document Library integration (app)](/integrations/sharepoint-documents/permissions-app.md)
