Frage

in Sharepoint 2013 i try to programmatically add a managed metadata column to a list using following code:

            Field f = list.Fields.AddFieldAsXml("<Field Type='" + columntype + "'   Name='" + columnname + "' DisplayName='" + columnname + "'  ShowField='Term1033' />", true, AddFieldOptions.AddFieldToDefaultView);

            clientContext.Load(f);
            clientContext.ExecuteQuery();

            TaxonomyField taxField = clientContext.CastTo<TaxonomyField>(f);

            taxField.SspId = this.getDefaultTermStoreId();
            taxField.TermSetId = getTermSetIdByName("Instanties");
            taxField.AllowMultipleValues = false;
            taxField.Open = true;

            taxField.TargetTemplate = string.Empty;
            taxField.AnchorId = Guid.Empty;
            taxField.Update();
            list.Update();
            clientContext.ExecuteQuery();

The column is created in my list as a managed metadata type column but the termset i want the users to choose from is not filled in in settings. Anyone has a hint to set the TermSet of the managed metadata column?

the getDefaultTermStoreId() and the getTermSetIdByName(string) give me the right GUID; i checked that!

thanks a lot!

War es hilfreich?

Lösung

We should add

taxField.TargetTemplate = string.Empty; taxField.AnchorId = Guid.Empty;

and then it works!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top