0

I have a SharePoint 2013 Multi Tenant environment. I have a Content Type Hub, a Root Site and a Document Center in addition to a Tenant Admin site in every tenant. I have a Custom Visual Studio solution for adding Content Types and Site Columns to my Content Type Hub. The Content Types and Site Columns are created declaratively in Visua Studio. These Content Types are pushed to the Root Site (and all the other subscribing sites within the tenant as well). The Root Site has the required lists, which use these Content Types. These lists have data now.

Now I have to make changes to the Content Types in the Hub by changing an existing column (say changing a column type from Single Line of Text to Multiline). I went back to my solution in Visual Studio and made the change to the Site Column declaratively. Now, I retracted and redeployed the solution and on feature activation, I published the Content Type, the subscribing site got this change and so did the list. Since it was a change from Single Line of Text to Multiline, there was also no data loss.

I also have to add a column now to the content type. After I did this in my Visual Studio project, I retracted and redeployed it and published the content type through the feature activation. I could see that the Root Site also got this change in it's Site Content Types list and I could see the newly added column. But, I was quite amazed to observe that the existing Content Type in the list is not showing the newly added column. But strangely, this works if I am adding a column to the content type through UI and then I am publishing it. I am not sure, what am I doing wrong here. Is there a way to achieve it, through code? I am sure there will be, since it is happening through UI. Please help.

PS: The site is live and hence I can't take any risk.

  • Could you please share the code you use to add column/edit SPContentType? Do you call myCT.Update(**true**)? – Evariste Jan 27 '16 at 10:51
  • We are using the Declarative approach for both the Content Type definition and the Column Definition. We use Visual Studio GUI to add the new Column to the Content Type. – Ven Jan 27 '16 at 12:11
0

Using the declarative (XML) based approach to create fields has always frightened me, and here's a new reason.

I really encourage people to use a pure imperative/C# approach (when possible, i.e. very often): creating a feature event receiver with code that creates artefacts by the mean of the server-side OM. That way, you control exactly what happens (including on feature-reactivation), you can debug, and there's no limitation... but that's another debate.

So back, to your case: did you use the AddContentTypeField tag in your elements.xml file to add your new field? And did you run a feature upgrade instead of deactivating/reactivating?
The proper way to add new fields on a CT during a feature update is described (fir instance) here: AddContentTypeField - cannot add field to Content Type (and in its answer).

  • I didn't. Is this really required? This requires too many steps like Content Type upgrade, feature upgrade and solution upgrade. These also look complex. Moreover, when I try to add a new column to a content type from UI, it works fine. Does it also do all these things behind the scenes? Moreover, I have my content types in my hub. They do get propagated to the subscribing sites, when the subscriber job runs, but only, they don't reflect in the list. Can you please provide some more details and links, which show how to do these in detail? – Ven Jan 27 '16 at 15:10
  • When you update your CT from the UI, it's like if you update with the server-side OM (myCT.Update(true)). They definetely don't use declarative code! That's why I largely prefer the C# code over XML implementation: you can do "the same as in the UI". If you have the problem you're facing, it's most probably because you don't update your feature with proper declarative elements. However, I agree the declarative approach is a real pain in the ass regarding updates (and other topics). In your case it's not too late to manage the update by code; however this will let you a "mixed" solution :( – Evariste Jan 27 '16 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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