TermSet.CustomSortOrder not using the default when created via creating a new page in a publishing site

Craig Vertigan 1 Reputation point
2020-08-26T05:04:51.863+00:00

I find that the term store sorting is buggy for publishing sites when creating a new page via the menu when navigation is set to this in the Site Settings\Navigation:

  • Add new pages to navigation automatically; and
  • Create friendly URLs for new pages automatically

When I create a new term directly in the term set it correctly uses the default sorting, which is: "Use default sort order according to current language", or it uses the custom sort order if I have previously set it to that. Ie it uses default if nothing was previously set (null) and it keeps it at whatever the current sorting is set at if it is already set because there are multiple terms in the branch.
But when I create a new web page using the "Add a Page" it always sets the sorting to "Use custom sort order". This renders the sorting setting in the term store completely useless because it never stays at the default setting.
Is there any way to get around this bug?
Microsoft have already said they think this is a "feature" not a bug. So I am left with trying to figure out if it is possible to check the sorting set on the parent term before the term & page are created and then after the term is created changing the sorting back to default if it was changed to custom, but leaving it as custom if it was already set at custom. But I'm not sure what kind of feature to create or how to go about this level of overriding OOTB SharePoint behaviour.

This appears to be the property I need to check on and then change afterwards:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.taxonomy.termset.customsortorder?view=sharepoint-server#Microsoft_SharePoint_Taxonomy_TermSet_CustomSortOrder
Or here
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.taxonomy.term.customsortorder?view=sharepoint-server

It states on that page that:
The value is a string composed of the child Microsoft.SharePoint.Taxonomy.TermGuid objects that are seperated by a :. When the custom sort order is a null reference (Nothing in Visual Basic) or empty, the child Term objects of the current Term is sorted alphabetically based on the working language of the current TermStore object.

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,607 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,941 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jerryzy 10,571 Reputation points
    2020-08-26T09:32:04.81+00:00

    Hi @Craig Vertigan ,

    I can reproduce this issue in my envrionment.
    After adding a page, the Managed Navigation will be always overrided to custom sort order rather than defult.
    A workaround solution is to change the sort order to default one using the code snippet below, leaving TermSet.CustomSortOrder to empty:

     using (SPSite site = new SPSite("http://sp/sites/publishingsite1"))  
                {  
                    TaxonomySession taxSession = new TaxonomySession(site);  
                    TermStore termStore = taxSession.TermStores["Mananged Metadata"];  
                    Group group = termStore.Groups["Site Collection - sp-sites-publishingsite1-1"];  
                    TermSet termSet = group.TermSets["publishingsite Navigation"];  
                    termSet.CustomSortOrder = "";  
                    termStore.CommitAll();  
                }  
    

    You can create an ItemAdded Event Receiver for the Pages library with the code snippet above so that this code function will be trigged automatically.


    If the response is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.