Search code examples
visual-studiosdkversionone

Adding a Link to a Story Using the VersionOne SDK


I am writing code to create a story in VersionOne, but I can't figure out how to add a link to the story.

The code I currently use to create the story is:

        part = snapHash.Split(":")
        snapHash = part(0) & ":<" & part(1) & ">" & part(2) & " / " & part(3) & " \ " & errorMessage

        connector = V1Connector _
            .WithInstanceUrl(ConfigurationManager.AppSettings("InstanceUrl")) _
            .WithUserAgentHeader("VersionOne", "1.0") _
            .WithAccessToken(ConfigurationManager.AppSettings("AccessToken")) _
            .UseOAuthEndpoints() _
            .Build

        services = New Services(connector)

        projectId = services.GetOid("Scope:" & ConfigurationManager.AppSettings("Scope"))
        storyType = services.Meta.GetAssetType("Story")
        newStory = services.New(storyType, projectId)
        newAttribute = storyType.GetAttributeDefinition("Name")
        newStory.SetAttributeValue(newAttribute, snapHash)
        newAttribute = storyType.GetAttributeDefinition("Source")
        newStory.SetAttributeValue(newAttribute, "StorySource:" & ConfigurationManager.AppSettings("StorySource"))
        newAttribute = storyType.GetAttributeDefinition("Description")
        newStory.SetAttributeValue(newAttribute, href)
        newAttribute = storyType.GetAttributeDefinition("Team")
        newStory.SetAttributeValue(newAttribute, "Team:" & ConfigurationManager.AppSettings("Team"))
        services.Save(newStory)

The href to VersionOne is being stored in the Description. I don't want to store the href in the Description, I want to add it as a link.


Solution

  • I figured it out after a lot of trial and error. After the new Story is save, call AcceptChanges() on the Story object. This provides the Oid you need for the next step, which is to create a LInk Asset and pass it the Oid for the story.

    connector = V1Connector _
        .WithInstanceUrl(ConfigurationManager.AppSettings("InstanceUrl")) _
        .WithUserAgentHeader("VersionOne", "1.0") _
        .WithAccessToken(ConfigurationManager.AppSettings("AccessToken")) _
        .UseOAuthEndpoints() _
        .Build
    
    services = New Services(connector)
    
    scopeOid = services.GetOid("Scope:" & ConfigurationManager.AppSettings("Scope"))
    storyType = services.Meta.GetAssetType("Story")
    storyAsset = services.New(storyType, scopeOid)
    newAttribute = storyType.GetAttributeDefinition("Name")
    storyAsset.SetAttributeValue(newAttribute, snapHash)
    newAttribute = storyType.GetAttributeDefinition("Source")
    storyAsset.SetAttributeValue(newAttribute, "StorySource:" & ConfigurationManager.AppSettings("StorySource"))
    newAttribute = storyType.GetAttributeDefinition("Description")
    storyAsset.SetAttributeValue(newAttribute, errorMessage)
    newAttribute = storyType.GetAttributeDefinition("Team")
    storyAsset.SetAttributeValue(newAttribute, "Team:" & ConfigurationManager.AppSettings("Team"))
    services.Save(storyAsset)
    storyAsset.AcceptChanges()
    
    linkType = services.Meta.GetAssetType("Link")
    linkAsset = services.New(linkType, scopeOid)
    newAttribute = linkType.GetAttributeDefinition("Asset")
    linkAsset.SetAttributeValue(newAttribute, storyAsset.Oid)
    newAttribute = linkType.GetAttributeDefinition("Name")
    linkAsset.SetAttributeValue(newAttribute, "SnapDumps Link")
    newAttribute = linkType.GetAttributeDefinition("OnMenu")
    linkAsset.SetAttributeValue(newAttribute, True)
    newAttribute = linkType.GetAttributeDefinition("URL")
    linkAsset.SetAttributeValue(newAttribute, href)
    services.Save(linkAsset)