Chat now with support
Chat with Support

Unified Communications Analytics 8.8.1 - Resource Kit

Using the Order clause to define sorting

Once you have all the main query criteria specified, the last step is a sorting definition. This definition returns the list sorted according to the specified AttributeName.

The syntax is simple, so an example will be enough:

UC Analytics supports only a single attribute name and a single attribute clause per query. As such, only a single sort order is supported. The Order clause is only applicable to Object queries. If you specify the Order clause in an aggregate query, the query will result in an error.

Working with the Query results

Once you have defined and run your query, the next step is to process the call results. The first step is to check the main result value from the query call. The result value should be an object and not the Null value. If you encounter a Null value, there is a problem. For information about what to check in this case, see the section titled Notes about using theOData client library .

The next step depends on the type of query you are running.

If you are running an Object query

The result of an object query is a collection of the object types that you specified in the query definition. The first step is to check for the number of returned objects. You can do this as follows:

This code goes with the example in the section that follows.

To get the records, you iterate through the items in the collection using the PowerShell ForEach item. The attributes on the iterated object are the same as those specified in the Select clause. As shown in the ObjectQuerySamples.ps1 sample file, this is done in the following way:

$messages = $clientLibrary.`

For("EmailMessages").`

Between($i_startDate, $i_endDate).`

Where($filter::Clause(`

"Recipients", $any, $filter::Clause(`

"EmailAddress.Person.Department", $equal, $i_department))).`

Select("Sender.EmailAddress.DisplayName", "SendDate", "Subject").`

QueryAllAsync().Result

Write-Host

ForEach ($message in $messages)

{

Write-Host $message.SendDate

Write-Host $message.Sender.EmailAddress.DisplayName

Write-Host $message.Subject

Write-Host

}

If you are running an Aggregate query

When you run an aggregate query, you are provided with a collection of results. These results represent the total number of objects that were used in the aggregation.

After you check the object count, check the Metric count. In the Metric value section, it shows that you can configure your query to have several metrics. For each metric specified in the Metric value, there is a Metric value in the Metric results collection. To get each metric, look at each item and look at the Group results:

Here is an example about how to access the main values:

$result = $clientLibrary.`

For("EmailMessages").`

WithinLast($i_numberOfWeeks, $weeks).`

Where($filter::Clause(`

"Recipients", $any, $filter::Clause(`

"EmailAddress.Person.Department", $equal, $i_department))).`

Count().`

Average("Size").`

QueryAsync().Result

if ($result.Metrics.Count -gt 0)

{

$metric = $result.Metrics[0]

Write-Host $metric.MetricId $metric.GroupResults.Value

$metric = $result.Metrics[1]

Write-Host $metric. MetricId $metric.GroupResults.Value

}

This results in two lines being written for each metric:

These lines are the total values of the aggregation. If your query contained a GroupBy clause, you can see the value for each item in the grouping by iterating through the Groups method of the GroupResults (shown previously).

For each Group, you can output the Key and Value pair. If you have included a Trending clause, you can look at the Groups collection of that object and output the Key and Value pair for the trended time frame. An example is shown in the AggregateQuerySamples.ps1 sample file, in the TrendAverageMessageDeliveryTimeByCountry method. See the following example:

$result = $clientLibrary.

For("EmailMessageParticipants").`

After($i_startDate).`

Average("DeliveryTime").`

GroupBy("EmailAddress.Person.CountryOrRegion").`

TrendBy("Message.Timestamp", $daily).`

QueryAsync().Result

Write-Host Total Messages: $result.TotalObjects

if ($result.Metrics.Count -gt 0)

{

$metric = $result.Metrics[0]

Write-Host $metric.MetricId : $metric.Value

ForEach ($countryGroup in $metric.GroupResults.Groups)

{

Write-Host $countryGroup.Key : $countryGroup.Value

ForEach ($dayGroup in $countryGroup.Groups)

{

Write-Host $dayGroup.Key : $dayGroup.Value

}

Write-Host

}

}

Related Documents

The document was helpful.

Select Rating

I easily found the information I needed.

Select Rating