Search code examples
c#sdkversionone

How to: Create an Asset using the VersionOne SDK


I’m trying to write some C# code to utilize the VersionOne SDK to create a Defect asset. I’ve queried our system and have identified the required attributes:

Defect derives from PrimaryWorkitem

  • Description : LongText
  • Name : Text
  • Parent : Relation to Theme — reciprocal of Children
  • Priority : Relation to WorkitemPriority — reciprocal of PrimaryWorkitems
  • Scope : Relation to Scope — reciprocal of Workitems
  • Source : Relation to StorySource — reciprocal of PrimaryWorkitems
  • Status : Relation to StoryStatus — reciprocal of PrimaryWorkitems
  • Team : Relation to Team — reciprocal of Workitems

Some of the values are obvious while others are somewhat abstract. For example, I’m not sure what to specify for the “Parent” attribute or the “Scope”. The documentation for creating an Asset with the SDK is pretty sparse. I can’t seem to find any code examples for using the SDK. At the moment, my code returns an exception:

The remote server returned an error: (400) Bad Request Violation'Required'AttributeDefinition'Parent'Defect

And, here’s the code I’m using at the moment:

static void AddV1Record(List<V1WerRecord> records)
        {
            V1Connector connector = V1Connector
                .WithInstanceUrl(VersionOneURL)
                .WithUserAgentHeader("VersionOneUpdate", "1.0")
                .WithUsernameAndPassword(VersionOneId, VersionOnePwd)
                .Build();

            IServices services = new Services(connector);

            Oid projectId = services.GetOid("Scope:0");
            IAssetType storyType = services.Meta.GetAssetType("Defect");
            Asset newDefect = services.New(storyType, projectId);
            IAttributeDefinition descAttribute = storyType.GetAttributeDefinition("Description");
            newDefect.SetAttributeValue(descAttribute, "My New Defect");
            IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name");
            newDefect.SetAttributeValue(nameAttribute, "My Name");
            services.Save(newDefect);

I understand the error is caused by not specifying all of the required attributes. I’m at a loss for what to specify for some of the attributes: Parent, Scope, etc.

Does anyone know of better documentation that explains using the SDK to create an Asset? Are there any good SDK examples/sample code available?


Solution

  • When creating a Primary workitem such as Defect or Story, you have to create it within the context of a particular project. The project is known at the system level as a Scope. A Parent attribute on a Defect is what is called a Theme. By default this is not a required attribute. Someone in your organization has declared this particular item as required.

    Parent: Relation to Theme means that the Parent attribute accepts a reference to a particular Theme. You would set the Parent attribute to something in the format like this

    Theme:1036

    This is called an OID. It is just a system ref to a table-like structure called a relation that holds all of the different Themes in your system. If you query your data API, you can get a list of all these Themes. The query looks like this

    yourVersionOneURL/rest-1.v1/Data/Theme?sel=ID,Name
    

    You will get an xml listing in your browser showing n number of these

    enter image description here

    So if I want to associate a Theme called Shirts with my Defect, I would set the Parent attribute to Theme:1036.

    You can add this to your code

    IAttributeDefinition parentAttribute = newDefect.GetAttributeDefinition("Parent");
    newDefect.SetAttributeValue(parentAttribute,”Theme:1036”);
    

    The same process goes for Scope. There is an alternative to querying. You can go into the VersionOne UI, find the name of the project (or other assets) that you need, hover the mouse over the project name (Scope) and in the status bar at the bottom of your browser you will see something that will indicate the Scope OID that is associated with that project name.

    I would chat with your VersionOne admin and get clarity as to why the required Theme is necessary for your organization