Skip to main content
System StatusContact Support
VersionOne Community

Executing Operations

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 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 using the Services object to 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 Reactivate operation using the Services object 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 the Delete operation using the Services object to 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.

  • Was this article helpful?