2

I have created a new work item type in XML, and imported it via Command Prompt: witadmin importwitd...

Let's say I have a field defined as such in the XML:

<FIELD name="severity" refname="MySeverity" type="String">
  <ALLOWEDVALUES>
    <LISTITEM value="High"/>
    <LISTITEM value="Medium"/>
  </ALLOWEDVALUES>
</FIELD>

Now, I want to modify this FieldDefinition, and add another LISTITEM to it, say "Low". I have found out that it could be done by changing the XML, and re-importing it. My question is, is there any way to do so programmatically in C#?

For further information, I've managed to query the field definitions via the following codes:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(my_uri));
WorkItemStore wistore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
WorkItemType witype = wistore.Projects["MyProject"].WorkItemTypes["MyWorkItemType"];
for (int i = 0; i < witype.FieldDefinitions.Count; ++i)
{
    FieldDefinition fd = witype.FieldDefinitions[i];
    // Not able to modify fd and save.
}

I'd appreciate if someone could shed some light on this. Thanks in advance!

2
  • I don't think this is possible (if my memory is correct, FieldDefinition is in read only mode). You should better try to modify your field via the XML via code rather than via TFS SDK.
    – Atlasmaybe
    Sep 10, 2013 at 7:50
  • Well, the list-items are actually based on some table's content. They have to be synchronized. If I update the list-items by updating the XML via codes, then I would also need to retain the WORKFLOW and FORM in the XML via codes. This is not desirable as I'd like to keep the form design and logic flows apart. Thanks for your response though!
    – Dunnomuch
    Sep 11, 2013 at 9:46

1 Answer 1

0

There is no way to modify list values programmatically. And if you want to synchronize the values with a table as you say then that would be impossible if you do it programmatically anyway as there is no way to store the table Id or code along with the field value.

If you really need the synchronization part then you may try using a crazy bit of workaround. You can store the allowed values using the xml as you normally do for display. After that in a separate group of allowed values you can specify a hidden index list of values for a user group name "xxxx" so that it doesn't show up. In this hidden list you can store the "TableId=ValueName" mapping of your current state of the table. Then the next time one of your fields gets modified you can refer this list and get the previous name of the value and modify it in the index and the display list. You can then use this same index list for maintaining the settings of your Workflow and FormLayout.

Refer the following example...

<ALLOWEDVALUES>
   <GLOBALLIST name="globalListName" />
   <LISTITEM value="Name1" />
   <LISTITEM value="Name2" />
   <LISTITEM value="Name3" />
. . . 
</ALLOWEDVALUES>

<ALLOWEDVALUES for="xxxxxx" expanditems="false">
   <GLOBALLIST name="globalListName" />
   <LISTITEM value="Id1=Name1" />
   <LISTITEM value="Id2=Name2" />
   <LISTITEM value="Id3=Name3" />
. . . 
</ALLOWEDVALUES>

Extremely out of the box but could be used if absolutely necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.