Share via


Activity Instance Data

Applies To: System Center 2012 - Orchestrator, System Center 2012 R2 Orchestrator, System Center 2012 SP1 - Orchestrator

The ActivityInstanceData entity represents detailed status information from an activity instance created by an Orchestrator runbook. The ActivityInstanceData collection includes all of the jobs run by the local Orchestrator environment. You can use the Data collection on an ActivityInstance entity to retrieve the activity instance data for a single activity instance.

Properties

The following table lists the properties of the ActivityInstanceData entity.

Name Type Key Description

ActivityInstanceId

GUID

No

Unique identifier of the activity instance the data came from.

Id

GUID

Yes

Unique identifier of the activity instance data item.

GroupId

Integer

No

Value

String

No

The value of the activity instance data item.

Relationships

The following table lists the entities that share a relationship with the Job entity and the key property in each entity used to define the relationship.

Collection Entity Relationship Related Entity Property ActivityInstanceData Entity Property

ActivityInstance

ActivityInstance

Parent

Id

ActivityInstanceId

Code Samples

Getting ActivityInstanceData using C#

The following code retrieves the activity instance data from a particular runbook instance using C#. This example uses a service reference named SCOService and uses the credentials of the current user context. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Programming in Visual Studio With the Orchestrator Web Service and Authentication and Authorization.

namespace CodeSample.Microsoft.SystemCenter.Orchestration.WebService
{
   using System;
   using System.Collections;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Net;
   using System.IO;
   using System.Data.Services.Client;
   using SCO.SCOService;   

   public class ActivityInstanceData
   {
      public static void Main()
      {
         Guid runbookId = new Guid("00000000-0000-0000-0000-000000000000");

         // Path to Orchestrator web service
         string serviceRoot = "http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc";

         // Create Orchestrator context
         SCOService.OrchestratorContext context = new SCOService.OrchestratorContext(new Uri(serviceRoot));

         // Set credentials to default or to a specific user.
         context.Credentials = System.Net.CredentialCache.DefaultCredentials;
         //context.Credentials = new System.Net.NetworkCredential("user", "pwd", "domain");

         // Setup Data Services query
         DataServiceQueryContinuation<RunbookInstance> nextRunbookInstanceLink = null;
         try
         {
            // Setup the query to retrieve the runbook instance. In this case, it’s the last instance to have run.
            RunbookInstance runbookInstance = (from rbkInstance in context.RunbookInstances
                                         where rbkInstance.RunbookId == runbookId
                                         orderby rbkInstance.CreationTime descending
                                         select rbkInstance).FirstOrDefault();

            // Query for the activity instances of the runbook instance
            IEnumerable<ActivityInstance> activityInstances = context.ActivityInstances.Where(ai => ai.RunbookInstanceId == runbookInstance.Id);

            // Output the properties of each instance to the console
            foreach (ActivityInstance activityInstance in activityInstances)
            {
                Console.WriteLine("Id: {0}, Status: {1}", 
                                   activityInstance.Id, 
                                   activityInstance.Status);

                // Get the data for each activity instance and output its properties to the console
                IEnumerable<ActivityInstanceData> activityInstanceData = context.ActivityInstanceData.Where(aid => aid.ActivityInstanceId == activityInstance.Id);
                foreach (ActivityInstanceData activityInstanceDataItem in activityInstanceData)
                {
                    Console.WriteLine("\tName: {0}, Value: {1}", 
                                         activityInstanceDataItem.Name, 
                                         activityInstanceDataItem.Value);
                } 
            }
         }
         catch (DataServiceQueryException ex)
         {
            throw new ApplicationException("An error occurred during query execution.", ex);
         }      
      }
   }
}

Getting ActivityInstanceData using Windows PowerShell

The following code retrieves the activity instance data from a particular runbook instance using Windows PowerShell. The example uses the credentials of the current user context. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Authentication and Authorization.

# Details of the runbook we want to get
$runbookId = "00000000-0000-0000-0000-000000000000"

# Create the request object for the runbook instance
$runbookInstanceUrl = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","Runbooks(guid'",$runbookId,"')/Instances")
$queryOptions = "?`$orderby=CreationTime desc&`$top=1"
$url = -join($runbookInstanceUrl,$queryOptions)
$request = [System.Net.HttpWebRequest]::Create($url)

# Set the credentials to default or prompt for credentials
$request.UseDefaultCredentials = $true
# $request.Credentials = Get-Credential

# Build the request header
$request.Method = "GET"
$request.UserAgent = "Microsoft ADO.NET Data Services"

# Get the response from the request
[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()

# Write the HttpWebResponse to String
$reader = [IO.StreamReader] $response.GetResponseStream()  
$output = $reader.ReadToEnd()  
[xml]$output = $output
$reader.Close()

# Get the runbook instance Id which we need for the next request
$runbookInstanceId = $output.feed.entry.content.properties.id.innertext

# Create the request object for the parameters
$activityUrl = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","RunbookInstances(guid'",$runbookInstanceId,"')/ActivityInstances")
$request = [System.Net.HttpWebRequest]::Create($activityUrl)

# Set the credentials to default or prompt for credentials
$request.UseDefaultCredentials = $true
# $request.Credentials = Get-Credential

# Build the request header
$request.Method = "GET"
$request.UserAgent = "Microsoft ADO.NET Data Services"

# Get the response from the request
[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()

# Write the HttpWebResponse to String
$reader = [IO.StreamReader] $response.GetResponseStream()  
$output = $reader.ReadToEnd()  
[xml]$output = $output
$reader.Close()

# Output properties of each parameter
foreach ($activityInstance in $output.feed.entry)
{
    Write-Host "Id: " $activityInstance.content.properties.Id.InnerText
    Write-Host "Sequence: " $activityInstance.content.properties.SequenceNumber.InnerText
    Write-Host "Start Time: " $activityInstance.content.properties.StartTime.InnerText
    Write-Host "Status: " $activityInstance.content.properties.Status
    
    # Create the request object for the activity data
    $activityDataId = $activityInstance.content.properties.Id.InnerText
    $dataUrl = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","ActivityInstances(guid'",$activityDataId,"')/Data")
    $request = [System.Net.HttpWebRequest]::Create($dataUrl)

    # Set the credentials to default or prompt for credentials
    $request.UseDefaultCredentials = $true
    # $request.Credentials = Get-Credential

    # Build the request header
    $request.Method = "GET"
    $request.UserAgent = "Microsoft ADO.NET Data Services"

    # Get the response from the request
    [System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()

    # Write the HttpWebResponse to String
    $reader = [IO.StreamReader] $response.GetResponseStream()  
    $dataOutput = $reader.ReadToEnd()  
    [xml]$dataOutput = $dataOutput
    $reader.Close()
    
    foreach ($data in $dataOutput.feed.entry)
    {
        Write-Host "`tName: " $data.content.properties.Name
        Write-Host "`tValue: " $data.content.properties.Value
    }
    
}

See Also

Concepts

Programming Using the Orchestrator Web Service
OData Queries Using the Orchestrator Web Service
Authentication and Authorization