Example #1
0
        public PickListMetadata Field_CreatePicklist()
        {
            List <PickListMetadata> pickListMetadata = null;
            PickList picklist     = null;
            string   pickListName = "colorsPicklist";

            VssConnection connection = Context.Connection;
            WorkItemTrackingProcessHttpClient client = connection.GetClient <WorkItemTrackingProcessHttpClient>();

            Console.Write("Searching to see if picklist '{0}' exists....", pickListName);

            pickListMetadata = client.GetListsMetadataAsync().Result;
            PickListMetadata item = pickListMetadata.Find(x => x.Name == pickListName);

            if (item != null)
            {
                Context.SetValue <Guid>("$picklistId", item.Id);
                Console.WriteLine("picklist found");

                return(item);
            }
            else
            {
                Console.WriteLine("picklist not found");
                Console.Write("Creating new picklist....");

                IList <string> list = new List <string>();

                list.Add("Blue");
                list.Add("Green");
                list.Add("Red");
                list.Add("Purple");

                picklist = new PickList()
                {
                    Name        = pickListName,
                    Items       = list,
                    Type        = "String",
                    IsSuggested = false
                };

                PickList result = client.CreateListAsync(picklist).Result;
                Context.SetValue <Guid>("$picklistId", result.Id);

                Console.WriteLine("done");
                return(result);
            }
        }