Posts

Showing posts with the label taxonomy

Sharepoint 2013 search filer and refine taxonomy managed metadata field equal exact match

if u'll use the "Search Query Tools v2", u'll find out an interesting thing, the results of an MMD field contains a strain of guids, and a single strain for word, the guids are the the guid of ur selected MMD and his childs. the string is the label. so what to so if you have a tree with lv1 say "Batman" and lv2 "Batman and Robin", and you want to retrieve only "Batman"? if you put the "Batman" guid u'll get many resutls, if you put "Batman" u'll get many results. looking in that awful string i noticed something, the really selected MMD has its guid twice, once usual, and the other with "0" (zero) before. so just put in your query "0" (zero) before the guid.

CreateTerm / CreateLabel error

in sharepoint 2013 taxonomy, i tried to add terms to an existing TermSet. the code i used gave me an arror                 string example = txtExample.Text;                 Term t = selectedT.CreateTerm(example, 1037);                 t.CreateLabel(example, 1037, true); where selectedT is just another term. the error i got "Violation of PRIMARY KEY constraint IX_ECMTermLabel_PartitionIdTermIdLCIDLabel Cannot insert duplicate key in object dbo.ECMTermLabel The duplicate key value is (0c37852b-34d0-418e-91c6-2ac25af4be5b, 607, 1037, 33)" the solution was NOT using CreateLabel.

Serialize (map) TermsSet / Term

i should edit this sometime, but currently here is the code public class ComplexMappedTerm { public static int LCID { get ; set ; } public Guid ID { get ; set ; } public string Label { get ; set ; } public int ChildrenCount { get ; set ; } public string Path { get ; set ; } public List < ComplexMappedTerm > Children { get ; set ; } private ComplexMappedTerm() { } public static ComplexMappedTerm BuildTree( TermSetItem tsi) { if (LCID == 0) { throw new ArgumentException ( "TermMap - Must set static property LCID before using mapping functions" ); } if (tsi is Term ) { return Map(tsi as Term ); } if (tsi is TermSet ) { return Map(tsi as TermSet ); } return null ; } static ComplexMappedTerm Map( Term t) { List < ComplexMappedT...

How to update TaxonomyField sharepoint 2013

the most simple solution, and occasionally the only working one, is to find the Term itself and send it and let SP to handle everything else, and the code is much shorter this is the code for updating the field Term ItemTypeTerm = GetTermByName() ; if (ItemTypeTerm != null ) {     TaxonomyField ItemTypeField =                     ( TaxonomyField )f.Fields.GetFieldByInternalName( "CbsMMDItemType" );       ItemTypeField.SetFieldValue(field, ItemTypeTerm); }

get TermSet Name (Label) by language (LCID)

today is a small story of how i won MS :) well i decided i want to make a custom navigation based on MMD, and with the site being with variations i need to be able to decide witch language i need. with Terms its pretty easy, you defauld method "GetDefaultLabel" accepts LCID, but with TermSet it just brings you the default language on the server, if the TermSet has one. finally i got help from my best friend, System.Reflection, and this is the code: Dictionary < int , string > names =     ts.GetType().GetProperty( "Names" ,     System.Reflection. BindingFlags .NonPublic |      System.Reflection. BindingFlags .Instance).     GetValue(ts) as Dictionary < int , string >; string label = names.Where(n => n.Key == lcid).First().Value;