posts - 16 , comments - 4 , trackbacks - 0

My Links

News

Tag Cloud

Archives

Post Categories

Set the default value to taxonomy site column or In the Library Field in the package

 

Set default value to taxonomy field

https://social.msdn.microsoft.com/Forums/sharepoint/en-US/5eaa5cc0-d9b1-42ed-9aed-ebb21345e859/how-can-i-set-the-default-value-of-taxonomyfield-mytaxofielddefaultvaluewssid-if-the-wssids?forum=sharepointdevelopmentprevious

Term defaultValue = terms[0];

TaxonomyField taxField

//Check and get the field value if already default value
TaxonomyFieldValue fieldValue = (TaxonomyFieldValue)taxField.DefaultValueTyped;
//Other use this
TaxonomyFieldValue fieldValue = new TaxonomyFieldValue(Field);
//Compose the fieldvalue (label | termguid)

string text = defaultValue.Labels[0].Value + TaxonomyField.TaxonomyGuidLabelDelimiter + defaultValue.Id.ToString();

fieldValue.PopulateFromLabelGuidPair(text);

//Check if the taxonomy term is not allready in the TaxonomyHiddenList of the rootsitecollection

int[] ids = TaxonomyField.GetWssIdsOfTerm(web.Site, store.Id, productenTermSet.Id, defaultValue.Id, true, 1);

if (ids.Length == 0)

{

//Set the WssId (TaxonomyHiddenList ID) to -1 so that it is added to the TaxonomyHiddenList

fieldValue.WssId = -1;

}

//Set the default value

taxField.DefaultValue = fieldValue.ValidatedString;
v

Print | posted on Monday, June 29, 2015 5:39 AM | Filed Under [ taxonomy sharepoint defaultvalue managed metadata ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: