I am trying to figureout have to convert this C# cost into powershell to create Envirmnent Library Fields
http://moss-net4u.blogspot.com/2012/02/creating-k2-environment-fields-with.html
In what DLLs are these methods in?
Create a new EnvironmentSettingsManager Instance
Create a new EnvironmentTemplateCollection Instance
Create a new EnvironmentInstanceCollection Instance:
Create new EnvironmentField instance by calling CreateFieldInstance()
The trick is to get a new instance of an Environment Field since is doesn’t have a new() constructor, you have to get a new instance by using the CreateFieldInstance() method of the EnvironmentFieldType class.
Steps:
- Create a new EnvironmentSettingsManager Instance and Connect to the K2 Server using the ConnectToServer() method of the EnvironmentSettingsManager instance.
- Create a new EnvironmentTemplateCollection Instance and a new EnvironmentInstanceCollection Instance.
- Select the Environment Template to use (e.g. Default Template) and select the Environment to use (e.g. Development)
- Get a handle on the EnvironmentFieldType you want to use by calling the EnvironmentSettingsManager.EnvironmentFieldTypes.GetItemByFriendlyName(“Miscellaneous Field”)
- Get a new EnvironmentField instance by calling CreateFieldInstance() method of the EnvironmentFieldType instance.
- Set the properties of the EnvironmentField instance
- Add the Field to the EnvironmentFieldCollection of the Environment Instance with the Add(newField) method of the EnvironmentFieldCollection
- Call the SaveUpdate() method of the EnvironmentField
Code:
EnvironmentInstance ei = new EnvironmentInstance();ei = eic.GetItemByName("Development");esm.ChangeEnvironment(ei.EnvironmentId);EnvironmentFieldType eft = esm.EnvironmentFieldTypes.GetItemByFriendlyName("Miscellaneous Field");EnvironmentField ef = (EnvironmentField)eft.CreateFieldInstance();ef.FieldName = "DeonTestField";ef.FieldDescription = "Deon Test Field";ef.DisplayName = "DeonTestField";ef.Value = "Some Value in Here";efc = new EnvironmentFieldCollection(ei);efc = ei.EnvironmentFields;efc.Add(ef);ef.SaveUpdate();