VersionOne - 使用VersionOne SDK将团队成员分配给Project

时间:2014-08-04 09:10:25

标签: versionone

需要使用API​​客户端将成员分配给项目。我试着吼叫。但它不起作用......

        Oid projectId = Oid.FromToken("Scope:1571", metaModel);
        Oid MemberID  = Oid.FromToken("Member:1594", metaModel);


        IAssetType scopeType = metaModel.GetAssetType("Scope");

        IAttributeDefinition atbAssignMember = scopeType.GetAttributeDefinition("Members");


        Asset newScope = services.New(scopeType, null);

        newScope.SetAttributeValue(atbAssignMember, MemberID);

Pease帮助我做到这一点。

由于

1 个答案:

答案 0 :(得分:0)

此代码段是如何将成员添加到项目的工作示例。你在设置属性。由于您的目标是创建多关系属性,因此您需要 AddAttributeValue 而不是 SetAttributeValue 。 SetAttributeValue保留用于单个/简单标量类型,如文本(即名称或日期)

        V1APIConnector dataConnector = new V1APIConnector("YourVersionOne/rest-1.v1/",
                                                         "LLuthor", "K!@#$1234");
        V1APIConnector metaConnector = new V1APIConnector("YourVersionOne/meta.v1/");
        IMetaModel metaModel = new MetaModel(metaConnector);
        IServices services = new Services(metaModel, dataConnector);

        Oid newMemberOid = Oid.FromToken("Member:1007", metaModel);
        Oid scopeId = Oid.FromToken("Scope:1489", metaModel);

        Query query = new Query(scopeId);
        IAssetType scopeType = metaModel.GetAssetType("Scope");
        IAttributeDefinition membersAttribute = scopeType.GetAttributeDefinition("Members");
        query.Selection.Add(membersAttribute);
        QueryResult result = services.Retrieve(query);
        Asset scope = result.Assets[0];
        scope.AddAttributeValue(membersAttribute,newMemberOid);
        services.Save(scope);