Sharepoint - Field appears twice on View / New Item

10,521

Solution 1

It is not wise to update the xml that creates the content type. If you want to add fields later on to the content type, do it through a new feature, see this link.

MSDN Article

Note the following text

Under no circumstances should you update the content type definition file for a content type after you have installed and activated that content type. Windows SharePoint Services does not track changes made to the content type definition file. Therefore, you have no method for pushing down changes made to site content types to the child content types. For information about best practices when making changes to content types that have been installed and activated, see Updating Content Types.

Solution 2

i got the same issue,after adding column in list definition, they starts appearing twice in new/edit/view item forms. I just changed the column ordering in list settings and the problem was solved.

Solution 3

Yepp, I´ve had those problems working with contenttypes added to lists. When I´ve made updates on the contenttypes somehow the I have sometimes gotten duplicates. When I have looked at them they seem to be the same Ids and Names but the id is actually different.

The solution that I´ve used (works with contenttypes at least) is to compare the fieldlinks on the site contenttypes with the fieldlinks in the actual xml file (feature) that contains the contenttype. If they are not the same number of fieldlinks...take actions to remove the duplicates.

Solution 4

1) First, I wanted to mention that I came across this issue as I was working towards making my MOSS 2007 solution package compatible with MOSS 2013. MOSS 2013 does not seem to like duplicate field names. So if you have custom fields that have the same name as a field that comes with MOSS 2013, you will get a duplicate field name was found error.

2) This forced me to have to go back and update my custom fields and content types. I came across the issue where my field names were appearing multiple times after making the changes to the custom fields that were causing the duplicate field name issue.

3) I wrote a web forms page to resolve the issue of having the field show up multiple times on your view, new, and edit forms. You just will have to modify the code to specify the list you want to check. This version will delete the first instance of the fieldref and keep the second instance:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;

using Microsoft.SharePoint;

using System.Text;
using System.Collections.Generic;



public partial class FixDuplicateFieldIssue : Microsoft.SharePoint.WebControls.LayoutsPageBase
{



    protected void Page_Load(object sender, EventArgs e)
    {
        if (SPContext.Current.Web.CurrentUser == null)
        {
            Response.Write("You must be logged in to view this page.");
            Response.End();
            return;

        }
        if (!SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.ManageWeb))
        {
            Response.Write("You do not have permissions to view this page.");
            Response.End();
            return;
        }

        lblOutput.Text = "";

        StringBuilder sbOutput = new StringBuilder();

        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        {
            using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
            {
                try
                {    
                    hlBack.NavigateUrl = web.Url;

                    //open the List  **** SPECIFY THE LISTNAME HERE ***
                    SPList spList = web.Lists["LISTNAME"];
                    if (spList != null)
                    {
                        //Check FieldLinks

                        sbOutput.Append("<table border='1'>");

                        foreach (SPContentType ct in spList.ContentTypes)
                        {
                            sbOutput.Append("<tr>");
                            sbOutput.Append("<td>" + ct.Name + "</td>");
                            sbOutput.Append("<td>");

                            Dictionary<string, Guid> GuidDictionary = new Dictionary<String, Guid>();   
                            List<Guid> RepeatList = new List<Guid>();
                            //SEARCH THE CONTENT TYPE FOR REPEAT SPFieldLinks
                            foreach (SPFieldLink spfl in ct.FieldLinks)
                            {
                                if (!GuidDictionary.ContainsKey(spfl.Name.ToLower()))
                                {
                                    GuidDictionary.Add(spfl.Name.ToLower(), spfl.Id);
                                }
                                else if (GuidDictionary[spfl.Name.ToLower()].ToString().ToLower()!=spfl.Id.ToString().ToLower())
                                {
                                    //Record the GUID of the repeat SPFieldLink you want to delete in the RepeatList.  In this case, we're recording the first item.  If you want to delete the second one, add the spfl.Id instead.
                                    RepeatList.Add(GuidDictionary[spfl.Name.ToLower()]);
                                    sbOutput.Append("<span style='color:red;'>*</span>");
                                }

                                sbOutput.Append(spfl.Name +  "," + spfl.Id + "," + spfl.DisplayName +"<br />");

                            }
                            sbOutput.Append("</td>");

                            sbOutput.Append("<td>");
                            sbOutput.Append("Repeats found: " + RepeatList.Count + "<br />");

                            //DELETE THE Repeat Field Links
                            foreach (Guid idToDelete in RepeatList)
                            {

                                sbOutput.Append("Deleting FieldRef with ID= " + idToDelete.ToString() + "<br />");
                                web.AllowUnsafeUpdates = true;
                                ct.FieldLinks.Delete(idToDelete);
                                ct.Update();
                                web.AllowUnsafeUpdates = false;

                            }
                            sbOutput.Append("</td>");




                            sbOutput.Append("</tr>");
                        }
                        sbOutput.Append("</table>");





                    }
                }
                catch (Exception ex)
                {
                    sbOutput.Append("Error Occurred: " + ex.ToString());
                }

            }
        }
        lblOutput.Text = sbOutput.ToString();

    }
}

Solution 5

Use this powershell script to clean dublicates:

Clear-Host
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 

$web=Get-SPWeb "http://weburl.here"

function cleanFieldLinks($listName){
    $list = $web.GetList($listName)
    $ct = $list.ContentTypes[0];

    $flDub = $ct.FieldLinks | group-object DisplayName | where { $_.Count -gt 1 }

    foreach($fl in $flDub)  {
        $skipFirst = $fl.Group | select-object -skip 1

        foreach($flDel in $skipFirst){
            $ct.FieldLinks.Delete($flDel.Id)
        }
    }   
    $ct.Update()

}

cleanFieldLinks("lists/listurl")
$web.Dispose()
Share:
10,521
Kobi
Author by

Kobi

My blog: ⚫ Regex for solving mazes ⚫ Why was I a fox? ⚫ Take photo, hear haiku ⚫ Recreational regex Answers: Regex + HTML ⚫ PCRE Grammar to .Net I’m 38 and live in Tokyo. Interested in programming, reading, privacy. My dream is making the world better using regular expressions. Mortal enemy of Sancho Panza. 🇮🇱➡️🇯🇵 Feel free to contact me: gmail: kobikobi twitter GitHub

Updated on June 04, 2022

Comments

  • Kobi
    Kobi almost 2 years

    I have a problem in a SharePoint list - some fields appear twice on the Display form, New Item form and on the list settings page. Both fields have the same ID and the same property page (same URL), so hiding one hides the other.
    Using SharePoint Manager I can only see one field, but maybe I looked at the wrong places? Has anyone experienced something similar, and how can I solve this issue?