---
id: executing-operations
slug: /sdk/dotnet/executing-operations
title: 'Executing Operations'
description: 'This topic explains about executing operations in Agility'
sidebar_label: 'Executing Operations'
sidebar_position: 8
tags: ['v1connectors', 'services']
---

This topic explains about executing operations in Agility.

## Overview

An operation is an action that is executed against a single asset. For example, to delete an asset you must execute the **Delete** operation on the asset. To close or inactivate a Workitem, you must use the **Inactivate** operation.

You can use the Meta API to determine the operations that a particular asset supports

Prior to executing an operation against an asset in Agility, you must first instantiate a **V1Connector** and **Services** object:

```
            V1Connector connector = V1Connector
            .WithInstanceUrl("<Server Base URI>")
            .WithUserAgentHeader("AppName", "1.0")
            .WithAccessToken("YOUR_ACCESS_TOKEN")
            .Build();
   
            IServices services = new Services(connector);
        
```

In versions of the SDK prior to the 15.0.0.0 release, you would also have to instantiate a connector for the**MetaModel**object. However, starting with the 15.0.0.0 release, that is no longer necessary.The**MetaModel**object is now available from the**Meta**property of the**Services**object.

## Closing an Asset

This example shows how to use the **Inactivate**operation usingthe **Services**objectto execute it against a Story:

```
                IOperation closeOperation = services.Meta.GetOperation("Story.Inactivate");
                Oid closeID = services.ExecuteOperation(closeOperation, services.GetOid("Story:1050"));
 
                Query query = new Query(closeID.Momentless);
                IAttributeDefinition assetState = services.Meta.GetAttributeDefinition("Story.AssetState");
                query.Selection.Add(assetState);
                QueryResult result = services.Retrieve(query);
                Asset closeStory = result.Assets[0];
                AssetState state = (AssetState) closeStory.GetAttribute(assetState).Value;
 
                Console.WriteLine(closeStory.Oid);
                Console.WriteLine(Enum.GetName(typeof(AssetState), state));

                /***** OUTPUT *****
                Story:1050
                Closed
                ******************/
            
```

## Reopening an Asset

This example shows how to use the **Reactivate**operation using the **Services**object to execute it against a Story:

```
                IOperation activateOperation = services.Meta.GetOperation("Story.Reactivate");
                Oid activeID = services.ExecuteOperation(activateOperation, services.GetOid("Story:1050"));
 
                Query query = new Query(activeID.Momentless);
                IAttributeDefinition assetState = services.Meta.GetAttributeDefinition("Story.AssetState");
                query.Selection.Add(assetState);
                QueryResult result = services.Retrieve(query);
                Asset activeStory = result.Assets[0];
                AssetState state = (AssetState)activeStory.GetAttribute(assetState).Value;
 
                Console.WriteLine(activeStory.Oid);
                Console.WriteLine(Enum.GetName(typeof(AssetState), state));

                /***** OUTPUT *****
                Story:1050
                Active
                ******************/
            
```

## Deleting an Asset

This example shows how to use the**Delete** operation usingthe **Services**objectto execute it against a Story:

```
                IOperation deleteOperation = services.Meta.GetOperation("Story.Delete");
                Oid deletedID = services.ExecuteOperation(deleteOperation, services.GetOid("Story:1050"));

                try
                {
                Query query = new Query(deletedID.Momentless);
                services.Retrieve(query);
                }
                catch(WebException)
                {
                Console.WriteLine("Story has been deleted: " + deletedID.Momentless);
                }

                /***** OUTPUT *****
                Story has been deleted: Story:1050
            ******************/
```

The **Delete** operation returns the Oid, with the new Moment, of the deleted asset. Future current info queries will automatically exclude deleted assets from results.
