Skip to main content
Version: Early Access

Executing Operations

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 VersionOne, you must first instantiate a V1Connector and Services object:

            V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.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 theMetaModelobject. However, starting with the 15.0.0.0 release, that is no longer necessary.TheMetaModelobject is now available from theMetaproperty of theServicesobject.

Closing an Asset

This example shows how to use the Inactivateoperation usingthe Servicesobjectto execute it against a Story:

                IOperation closeOperation = services.Meta.GetOperation("Story.Inactivate");
Oid closeID = services.ExecuteOperation(closeOperation, "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 Reactivateoperation using the Servicesobject to execute it against a Story:

                IOperation activateOperation = services.Meta.GetOperation("Story.Reactivate");
Oid activeID = services.ExecuteOperation(activateOperation, "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 theDelete operation usingthe Servicesobjectto execute it against a Story:

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

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

/***** OUTPUT *****
Story has been deleted: Story:1049
******************/

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.