简体   繁体   中英

Modify FieldDefinitions programmatically

There is currently a need within our shop to be able to add/modify/delete the FieldDefinitions on a WorkItemStore programmatically, without/before messing with the WorkItemType definitions. Is this possible? I know that i can GET all the fields on a project and see them, but what about adding new ones, or modifying existing ones ? (delete not as important).

i've been searching google for the past 2 days and couldn't find what i'm looking for...

Right now, this is how i am reading all the fields from the server.

List<FieldDefinition> all_defs = new List<FieldDefinition>();
FieldDefinitionCollection defs = wis.FieldDefinitions;
foreach(FieldDefinition def in defs)
    all_defs.Add(def);

I was able to do a workaround. Basically, in code, I was able to get all of the fields on the server, create all of the fields that I needed to add or modify and then export one WIT as XML into a separate string.

From there, I extracted the new fields that I needed by comparison, modified the fields that I needed to modify (in Xml), changed the name of the WIT (in Xml) into a temporary one (eg: Missing_fields), then modified the WIT Xml to include both the new fields and the modified ones inside the Fields tag...

Then I used the Import WIT method on the temporary WIT I just created...

Then I refreshed the connection cache for the API... (this ensures the API has access to the new WIT so we can delete it)

Then I used the DestroyWIT action package to destroy the temporary WIT from the server, which essentially destroys the WIT itself, but not the fields as those are a separate entity on the server, and voilà! You've got yourself a FieldDefinition import and modify tool.

I still can't delete but that's not too bad...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM