Edit SharePoint Field properties, including lookup column list association, with client side code only

20.10.2010 Updated code to add some more features: Edit list properties: “Hidden”, “ShowUser”, “Ordered”, “Direction”. Field properties: ShowInDIP (document information panel) and cross site lookup functionality for a standard SharePoint lookup column. The article is updated and describes the changes.


This code enables you to edit the following using javascript/jQuery only

List properties:

  • Hidden: Hide the list so that it does not appear on the Documents and Lists page, Quick Launch bar, Modify Site Content page, or Add Column page as an option for lookup fields.
  • ShowUser: Specify that names of users are shown in “Created by” and “Modified by” fields.
  • Ordered: Specify that the option to allow users to reorder items in the list is available on the Edit View page for the list.
  • Direction: LTR if the reading order is left-to-right, RTL if it is right-to-left.

Field properties:

  • Hidden: Specifies whether the field is displayed in the list.
  • ReadOnly: Specifies whether values in the field can be modified.
  • Required: Determines whether the field requires values.
  • Show In NewForm: Specifies whether the field is displayed in the form that is used to create list items.
  • Show In DispForm: Specifies whether the field is displayed in the form for displaying list items.
  • Show In EditForm: Specifies whether the field is displayed in the form that is used to edit list items.
  • Show In DIP: Specifies whether the field is displayed in the “Document Information Panel” in compatible Microsoft Office applications. Only available for document libraries.
  • Show In List Settings: Specifies whether the field is displayed in the page for customizing list settings.
  • Show In Version History: Specifies whether the field is displayed in the page for viewing list item versions.
  • Show In View Forms: Specifies whether the field is displayed in pages that are used to view list data.
  • Lookup column web and list association (cross site lookup): Change the web and list association for a lookup column – Note: If you do this, all existing elements in this column will be lost. The cross site option is only available for site collection administrators!

Images:

IMG


IMG


IMG


Disclaimer:
I have removed some list types and some column types, but be careful using this tool. Test this in a “test list” before you use it in your “production environment”. If you edit the wrong field, you could break the list. Use this tool at your own risk!

Create a WebPartPage, insert a CEWP, and paste the code.
You find the code here

Regards
Alexander

78 Comments on “Edit SharePoint Field properties, including lookup column list association, with client side code only

  1. Hi,

    this is exactly what i need and searched for the last week. But unfortunatly it doesn`t work.

    I checked the path to the jquery file and it is correct, it also shows the changed column green when i click on the Save Button. But the changes doesn’t seem to be saved.

    I selected a field in a Tasklist not to be shown on DispForm, but it is still there.

    I use WSS 3.0 to test this.

      1. I am missing the select list options
        I just get a select list to start:
        v3.2 below it
        but not possible to select a list what am I doing wrong please help 🙁

  2. Hi Alex,

    As always, you have created an amazing piece of code!
    I have this code working as advertised except I am experiencing the diappearance of anything I set to ReadOnly.

    Have I done something wrong?

  3. Hi Again,

    Your code is some of the only ones I have found that WORK!

    My apologies if I am wasting your time, but I am afraid I do not understand the ReadOnly working the same as Hidden. Can the ReadOnly be changed to Display only. For example I want users to SEE the fields contents but I don’t want them to be able to edit it. I am hoping that it could perform what the code below achieves.

    Thank you very much!
    Will

    READ ONLY Code example

    function check()
    {
    var elements=document.body.getElementsByTagName(“*”);
    for (index=0; index < elements.length;++index)
    {
    if(elements[index].tagName=="INPUT" && elements[index].type=="text" && (elements[index].title=="MTGID" || elements[index].title=="PRJID" ))
    {
    elements[index].readOnly=true;
    }
    }
    }
    _spBodyOnLoadFunctionNames.push("check()");

  4. Fantastic! Is it possible to use this to “Show in Alerts”? I haven’t been able to find anything to help control the appearance of alerts and my html calculated columns show up there and look terrible. Thank you for all that you do!

  5. Terrific Job, It is one of the best post. Can you please let me know how can i hide or remove Title, All Day Event, Recurrence, Workspace fields from Calendar. I dont want this feilds to show up in any of the forms i.e new, dispform, allitems, edit.

    I really appreicate if you could quickly post some solution to it.

    1. Hey John, this is a fairly simple code using what Alexander has already posted. If you start to familiarize yourself with jQuery it will get easier. When you implement this code make sure of 2 things. Node of the fields you hide are set to required. and add this to all 3 forms (New, Disp and Edit)

      update your src reference

      <script type="text/javascript" src="/sites/globalmp/JavaScripts/jquery-latest.min.js"></script>  
      <script type="text/javascript">  
      fields = init_fields_v2();  
      
      $(fields['Title']).hide();
      $(fields['fAllDayEvent']).hide();
      $(fields['fRecurrence']).hide();
      $(fields['WorkspaceLink']).hide();
      
      function init_fields_v2(){  
           var res = {};  
           $("td.ms-formbody").each(function(){  
           var myMatch = $(this).html().match(/FieldName="(.+)"s+FieldInternalName="(.+)"s+FieldType="(.+)"s+/);  
              if(myMatch!=null){  
                   // Display name  
                   var disp = myMatch[1];  
                   // FieldInternalName  
                   var fin = myMatch[2];  
                   // FieldType  
                   var type = myMatch[3];  
                   if(type=='SPFieldNote'){  
                       if($(this).find('script').length>0){  
                           type=type+"_HTML";  
                       }  
                   }  
                   if(type=='SPFieldLookup'){  
                       if($(this).find('input').length>0){  
                           type=type+"_Input";  
                       }  
                   }  
                   // Build object  
                   res[fin] = this.parentNode;  
                   res[fin].FieldDispName = disp;  
                   res[fin].FieldType = type;  
               }  
           });  
           return res;  
       }  
      </script>
      
  6. wow this is really cool .. i m new into sharepoint and coding is a bit tough job form me .. sorry to bother u but can u plz tel why cant we use server side code .. as dis is so tough

    1. Hi, Server side code is no problem to use if you have access to the server. In *most cases* the end user does not have access to put files on the webserver.

      Alexander

  7. Great script… I liked it very much, it solved my big problem… ::YOU ARE MY FIRST SHARE POINT GURU(TEACHER)::

    Thanks for sharing the great script.

    A quick Query: Could you please tell me how to only display my own lists? how do I get the number of my list as you written in script?

    var arrTypesToSkip = [‘110′,’111′,’112′,’113′,’114′,’115′,’116′,’117′,’118’];

    1. Hi,
      Sorry for the late reply, but your question drowned in all the emails and comments…

      These are not lists, but list types. I’m not sure what you mean by “your own lists” as the list does not have any records of the user who created it.

      Alexander

  8. Hi Alex

    Great script. Can you advise why Calculated Field type do not show? I’m using some Text2HTML stuff and I don’t want fields like ‘Color’ to show up. I’m having to edit the forms individually to hide the field and it would be good if I could manage them through this script.

    1. Look at line 213 in the script. If you remove “Calculated” from the “arrOfTypesToSkip” you will see your calculated fields alongside many “system fields”. You better not change the “system fields” as you can end up messing up the list for good.

      Alexander

  9. Thank you so much for your solution! I have been scraching my head for a while now and found this… Amazing!!! I do have a question: Once I set a field to “read only” it is not listed in edit mode. Is there a way around that?

    Best Regards,
    M

  10. gud article. i have one query like there are 2 users ie user1 and user2.
    the user 1 should have to enter or edit xyz
    and user 2 should have to enter or eidt abc.
    is it possible? Please suggest how to do it.

    1. Hi,
      This is a power user / site collection administrator tool, but if the user is not site collection administrator, setting the list permissions might work (if xyz and abc is lists).

      Alexander

  11. This is great — and works great on an HTTP site. Does anyone have any experience or suggestions to get it working on an HTTPS site? Changing the references to HTTPS in the JS didn’t help me. 🙂

    Thanks.

    -Ray

  12. I created a test list.

    It looks like it will let me pick a subsite.

    But nothing has changed on my test list. Is there some other step I’m missing?

  13. It’s a brilliant bit of code. Unfortunately in SP 2010, you set a field to read only and display in editform, and it no longer appears in editform. Seems like an SP bug to me.

    So all I could do was make a new edit form (which is detached sadly – won’t reflect future column changes) then edit the field settings in SharePoint Designer.

  14. I was trying to set the Hidden property to Yes for several system created Libraries like “Site Collection Documents” and “Site Collection Images” which are part of the “Publishing Resources Feature” and I get an Error Occured response from the script. Is that expected? Thanks!

    1. Hi,
      Sorry for the late reply. I’m not familiar with the “Publishing Resources Feature”, but it might be that these columns are not editable.

      Alexander

  15. Hi,
    I’ve tried to implement your solution, but get “Web selector not available” in the ‘lookup column list association’ column, so can only choose a list on the same site collection. Any idea what is causing this and how, if at all, I can fix this? PS I don’t have access to the server. Thanks.
    Paul

  16. Hi Alexander,

    I created a CEWP on a web page and pasted the script onto it, expecting the joy that everyone here experienced–but unfortunately, no joy. The CEWP just displaed the text of the script and didn’t resolve the tags into a page like you displayed in your screen images above. Just everything from to
    Next, I saved the script as EditFieldProperties.js file onto my computer and uploaded it to a document library on our SP site called Site Assets. I then referenced the path from the Site Assets library in the CEWP, and all that happend was a link to EditFieldProperties.js appeared on the CEWP.
    I am sure it is some newbie thing I am missing. So any further detail would be greatly appreciated.

    Thanks,

    Richard

      1. Thanks Alexander! The HTML Form Web Part actually worked.
        The reason I needed this was because, for some reason, the built-in SP “Modified By” column was somehow set to Required. Well, when I got the script to work, the “Modified By” column and its properties are not being displayed. So, is the “Modified By” column somehow being filtered out by the script? If so, what changes do I need to make to the script so that I can see the “Modified By” column? I just thought that was the case because of the caveat at the beginning of the script (i.e. “I have removed some list types and some column types”)

    1. Hi,
      Yes, these fields has been removed. You can add them back by editing the script – change this line:

      var arrOfAdvancedFields = ['Author','Created']

      to

      var arrOfAdvancedFields = ['Author','Created','Editor']

      I do not think this will fix your problem, as this column is not set as required by default. Please be careful, you might break your list.

      Alexander

      1. Thanks Alexander! I will try that and be extra careful.
        I am not sure either why or even how the “Modified By” column was set to “Required”. Any thoughts? In my search for an answer, Google has brought me here. Any other less riskier ideas or solutions.
        I tried changing the Manage Content Type to “Yes” within the list’s Advance Settings and change the property there… but no such luck. When I open the list’s form in InfoPath, I still see the field as having a red asterisk for required. Saving a new record is impossible because the required constraint is being violated. So, I am desperate.
        I’ll try this tonight.

      2. Out of curiosity, worst-case scenario, how might a list be rendered broken by the changes made by the script?

  17. Greate solution Alexander! You have done a great job here!

    I have tested it on SharePoint 2010 and it works as described. Do You have any plans for converting it to SharePoint 2013? It would really be helpful

    Regards, Magnus

    1. I’m trying your script in SharePoint 2013. I’ve added a CEWP to the default new form and added a link to the JS file (in site assets) in the content link and I can click to load list collection and all I get is please wait while loading lists.
      I did replace the two enteries _spUserId with _spPageContextInfo.userid.
      Any Ideas?

      1. Hi,

        I used Script Editor to insert the script into the page and that worked for me.

        Regards,
        Vladimir

      2. I also tried the script editor and I still get “please wait while loading lists”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.