使用VersionOne SDK向故事添加链接

时间:2019-09-26 14:50:10

标签: visual-studio sdk versionone

我正在编写代码以在VersionOne中创建一个故事,但是我不知道如何向该故事添加链接。

我当前用于创建故事的代码是:

        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)

VersionOne的href存储在描述中。我不想在说明中存储href,我想将其添加为链接。

1 个答案:

答案 0 :(得分:0)

经过反复试验,我弄清楚了。保存新的故事后,请在故事对象上调用AcceptChanges()。这为下一步提供了所需的Oid,即创建LInk资产并将其传递给故事的Oid。

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)