5

I am facing this strange behaviour on my SharePoint Farm 2013 On-Premises. Below are the steps I followed:

  1. I create a new Site Content type which have the Issue content type as its the parent.

  2. Now based on the customer requirements, the Item titles had to be system generated.

  3. So I set a default value for the Title Site Column where I entered ', and I wrote an event receiver which will set the item title. and I left the Title Site Column as required.

  4. Then in my custom content type i set the Title as hidden.

  5. And then, in a sub-site I created a new custom list >> I set its content type as my new custom content type, and I remove the "item" content type from the list.

  6. I did a test , where i added a new item >> the title was hidden from the create form, and the event receiver set the item title value. and everything was working well.

So at that stage I have the following settings:-

  • The Title site column at the site level, has the following properties:-

    • Required (this is default).
    • I set a default value for it = '. so the ER will update the Title based on certain criteria.

Now I save the Site as Template, then I created a new site based on the template. But on the new site I have noted that the Title will be shown inside the Create form and also the "Editor comments" field, although I set it a hidden inside the content type.

So can anyone please share an advice on this ? Why the Title Settings are not being preserved inside the Site Template ???

Now I know that I can go to the Site Content Type and set the Title to be hidden again and have the result on all the underlying sites, but I need this to be preserved inside the Site Template.

2 Answers 2

3

As I mentioned in a question you asked earlier, I had the same problem. I have only been able to solve it with an "unsupported" action. But it works perfectly. In my case it is a multi-site project management solution, in which I have been working for years on SharePoint 2010.

This is the code I used. It may vary depending on the type of column to use.

SPList list = newSite.Lists.TryGetList("myList");
SPField titlefield= list.Fields["Title"];
if (!titlefield.CanToggleHidden)
{
  Type type = titlefield.GetType();
  MethodInfo mi = type.GetMethod("SetFieldBoolValue", BindingFlags.NonPublic | BindingFlags.Instance); 
  mi.Invoke(titlefield, new object[] { "CanToggleHidden", true });
}
titlefield.Required = false;
titlefield.Hidden = true;
titlefield.Update();
0
1

Is Hidden what you want? Setting the field to hidden prevents the data from being indexed in search etc.

Moreover, save site as template has honestly never worked for me. There are too many variables users can change to break it.

The Field & FieldRef level schema attributes ShowInEditForm, ShowInDisplayForm are more appropriate if you want to hide a field from that part of the UI. As you're exporting the site as a template I'm not sure that's something you want to change but you could build a List Definition that included the content type with list level field settings setup appropriately:

Refer this and this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.