2016-10-21 10 views
0

を必要とされていないフィールドを、返します。validateメソッドは、私は同じようにそれを設定し、私は新しい作業項目を作成していた場合

WorkItem workitem = new WorkiItem(workItemType); 

そして、私は単純に直接検証することにより、必要なすべてのフィールドを取得していますので、私保存する前に入力する必要があるフィールドを知っています。

ArrayList requiredFields = workitem.Validate(); 

しかし、私のrequiredFieldsの内側には、fielddefinitionの必須フィールドとしてマークされていないフィールドがあります。たとえば、フィールド "Assigned To"は必須フィールドではないので、このフィールドを埋めることなくTFS-Webアプリケーション内に作業項目を作成することができます。それで、検証中にrequiredFieldリストに入れられるのはなぜですか?検証されていなければ、私はそれを保存したくありません。

+0

可能な重複:フィールドは異なる検証作業項目の現在の状態(オプション1)に基づく要件や現在のユーザーの権限(オプション2)次のコードは、ご参考のため、この二つのオプションのための一例であるを持つことができます[WorkItemの必須フィールドを取得する](http://stackoverflow.com/questions/21621866/get-required-fields-for-some-workitem) – DaveShaw

+0

検証された作業項目の種類は何ですか?一部の作業項目タイプには[割り当て先]フィールドが必要です。 –

答えて

0

WorkItemの検証は、WorkItemTypeのテンプレートで定義されています。の

// Set the following variables accordingly 
     string workItemTypeName = "Bug"; 
     string teamProjectName = "My Project"; 
     string usernameToImpersonate = "XXX"; 
     string tfsTeamProjectCollectionUrl = "http://xxx:8080/tfs/defaultcollection"; 

    // OPTION 1: no impersonation. 
    // Get an instance to TFS using the current thread's identity. 
    // NOTE: The current thread's identity needs to have the "" permision or else you will receive 
    //  a runtime SOAP exception: "Access Denied: [username] needs the following permission(s) to perform this action: Make requests on behalf of others" 
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsTeamProjectCollectionUrl)); 
    IIdentityManagementService identityManagementService = tfs.GetService<IIdentityManagementService>(); 

    // OPTION 2: impersonation. Remove the following two lines of code if you don't need to impersonate. 
    // Get an instance to TFS impersonating the specified user. 
    // NOTE: This is not needed if the current thread's identity is that of the user 
    //  needed to impersonate. Simple use the ablve TfsTeamProjectCollection instance 
    TeamFoundationIdentity identity = identityManagementService.ReadIdentity(IdentitySearchFactor.AccountName, usernameToImpersonate, MembershipQuery.None, ReadIdentityOptions.None); 
    tfs = new TfsTeamProjectCollection(tfs.Uri, identity.Descriptor); 

    WorkItem workItem = null; 
    WorkItemStore store = tfs.GetService<WorkItemStore>(); 

    // Determine if we are creating a new WorkItem or loading an existing WorkItem. 
    if(workItemId.HasValue) { 
     workItem = store.GetWorkItem(workItemId.Value); 
    } 
    else { 
     Project project = store.Projects[ teamProjectName ]; 
     WorkItemType workItemType = project.WorkItemTypes[ workItemTypeName ]; 
     workItem = new WorkItem(workItemType); 
    } 

    if(workItem != null) { 

     foreach(Field field in workItem.Fields) { 
      if(field.IsRequired) { 
      // TODO 
      } 
     } 
    } 
+0

これは役に立つと思われますが、workItemId変数はどこにありますか? –

+0

既存のworkItemを取得する方法を理解できるように、workItemIdを例として使用します。アプリケーションで既存の作業項目の編集がサポートされている場合は、既存の作業項目を取得して、どの項目が必要かを確認する必要があります。新しい作業項目のみを作成する場合は、yes(workItemId.HasValue)を使用する必要はありません –

+0

詳細はこのチュートリアルを参照してください。https://blog.joergbattermann.com/2016/05/05/vsts -tfs-rest-api-06-既存の作業項目の検索と照会/ –

関連する問題