Sharepoint - Field appears twice on View / New Item
Asked Answered
H

5

5

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?

Hoxha answered 10/6, 2009 at 8:14 Comment(0)
I
4

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.

Intention answered 10/6, 2009 at 8:48 Comment(1)
The problem existed on production, and we had real data. We created new columns and copied the data to them, and deleted the duplicated columns. So, in a way, your solution is what we did - nothing. :-)Hoxha
A
7

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.

Anneliese answered 22/8, 2011 at 13:30 Comment(1)
Interesting workaround, thanks. I actually know of several problems in SharePoint that can be solved by exactly that...Hoxha
C
5

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.

Concentration answered 10/6, 2009 at 8:31 Comment(2)
Hello Johan, thanks! You are absolutely right, btw, this is a content type added to the list by a feature (not mine, though). Where can I find these fieldlinks? Is it done programatically?Hoxha
I mean <FieldRefs> if you know them. Links to the fields used in the contenttype. Since you don´t have access to the actual feature I would recommend Colin´s solution in this case. My solution isn´t really supported, but what is anyway...in SharePoint we need to go around the obstacles anyway we can... :-)Concentration
I
4

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.

Intention answered 10/6, 2009 at 8:48 Comment(1)
The problem existed on production, and we had real data. We created new columns and copied the data to them, and deleted the duplicated columns. So, in a way, your solution is what we did - nothing. :-)Hoxha
W
2

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()
Widthwise answered 26/11, 2013 at 8:26 Comment(0)
C
2

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();

    }
}
Chalcis answered 7/5, 2015 at 5:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.