sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Custom contenttype is not actually attached to the list when using SPFx asset provisioning

Open justdevelopment opened this issue 8 years ago • 13 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

Custom ContentType should be attached to a newly create list on asset creation or if not possible, added after it has become available to the list through some sort of timerjob?

Observed Behavior

The list is created, all columns are added according to ContentType but the ContentType itself is not added to the list. It has been created within the site collection but also cannot be added manually (unavailable in options) to the list. After some time the ContentType is suddenly available in the settings and can be added.

Steps to Reproduce

  • Create a SPFx webpart. I’ve made a really simple demo based on the docs here; Github repo
  • Upload the app as you would normally and install it in the web.
  • After it has been installed on the web, see that the list has been created and contains all columns.
  • When you add a new item or go to list settings; see that ContentType has been enabled but only ‘Item’ is there.

image

  • Go to Site Settings and check the available ContentTypes; see that our custom one is added to the group 'SPFx Content Types' image

  • Go to list settings and choose to add an existing ContentType

  • See that our new custom ContentType is not available for selection in the settings (notice that the new group is also unavailable). image

  • Wait 30-60 min, repeat above steps and now you can add the new ContentType to the list.

justdevelopment avatar Mar 22 '18 14:03 justdevelopment

You should just need to add EnableContentTypes in your schema.xml file: <List EnableContentTypes="TRUE"

After doing that it should work.

GrahamMcMynn avatar Mar 22 '18 17:03 GrahamMcMynn

It is set to true: https://github.com/justdevelopment/SPFxAssetDemo/blob/master/sharepoint/assets/schema.xml

ContentTypes have been enabled for the list, it's just not adding a custom one.

justdevelopment avatar Mar 22 '18 17:03 justdevelopment

@justdevelopment - thanks for the response, we will take a look at this as it seems like an issue.

GrahamMcMynn avatar Mar 27 '18 17:03 GrahamMcMynn

Hi guys. Any news on this issue? I am trying to accomplish the same in another solution, but am still left with only "Item" as the single available Content Type. The fields however, are provisioned as expected.

balle3201 avatar Apr 27 '18 12:04 balle3201

@justdevelopment / @balle3201 Ok well I don't have issues. Item has been extended. In list settings i also only see "Item". What you are seeing is the extension of Item through your Content Type. And because there's an Item on every list, Item becomes Item. Inheritance right?

listsetting Click on Item (see above graphic) . . . This screen now shows the extended Item, inherited through your custom content type which inherits from the Site Content Type: Item. Notice the Parent is your custom content type. In my case I called it "Footer".

listcontenttype Click on Parent: Your Custom Name ( see above graphic) . . . boom

and there she is.. inheriting from Item and passing that down and so on... works for me and makes sense.

Basically:

  • Item ( Site Content Type )

    • Footer ( Custom Content Type )

      • Item ( List Content Type )

        • Custom List ( inherits from above )

It's just like normal, except that your Custom Content Type has been inserted between Item (Site) and Item (List) as above.

Inheritance of columns from Item as well as your **Custom Content Type's ** associated columns.

I think you assumed that when you saw Item (List Content Type) that it inherited from Item (Site Content Type) as per normal when you manually create a new custom list in the UI. You were probably expecting to see your Custom Content Type below Item in List Settings.

Hope this helps clarify? If not, apologies in advance for the spam :)

UX-Gav avatar May 31 '18 16:05 UX-Gav

You're right, it does seem to inherit from the created contenttype (nicely spotted!), but that still isn't expected behavior. We want it to be the contenttype we create by name, not as 'Item'. Plus, it's weird that when you manually add the newly created contenttype you can only do so after X minutes and then it works exactly as expected and as in previous SharePoint versions.

I haven't done any further testing yet, but I am wondering now what will happen if you add two custom contenttypes. Will all columns be added to Item, how will it inherit then? Or do you get two 'Item' contenttypes? Did you perhaps test this scenario? If not, we will do some tests to find out :)

justdevelopment avatar Jun 04 '18 10:06 justdevelopment

Hi. Haven't tested the scenario with multiple content types yet. I'll let you have a bash and let us know :)

UX-Gav avatar Jun 04 '18 11:06 UX-Gav

I can still replicate this issue while provisioning assets. Was the fix made or is it the itended behaviour that we will see Content Type name as "Item" derived from our custom content type "x". I have the exact situation as @UX-Gav has explained.

mjmohitjoshi avatar Apr 11 '19 15:04 mjmohitjoshi

I completely forgot about this ticket... Oops?

So we did manage to figure out a way to get it to work correctly: use the entire ContentType in your listschema, not the ContentTypeRef.

So here in this file we have a ContentTypeRef:

<ContentTypeRef ID="0x010042D0C1C200A14B6887742B6344675C8B" />

It should actually be this instead:

 <ContentType ID="0x010042D0C1C200A14B6887742B6344675C8B"
           Name="Cost Center"
           Group="SPFx Content Types"
           Description="Sample content types from web part solution">
       <FieldRefs>
           <FieldRef ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}" />
           <FieldRef ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}" />
       </FieldRefs>
   </ContentType>

Now your list will get created with the proper contenttype attached, all fields as they should be and no 'Item' in sight.

justdevelopment avatar Apr 11 '19 16:04 justdevelopment

Do I have to make a corresponding change in Elements.XML as well? After making your suggested change, I have same XML structure of ContentType tag both in Elements.XML and Schema.XML

CT

mjmohitjoshi avatar Apr 12 '19 11:04 mjmohitjoshi

That's correct, you will have the same in both files. This way you will get the site content type and a list content type that inherits from that.

On Fri, 12 Apr 2019, 13:54 mohitcreative, [email protected] wrote:

Do I have to make a corresponding change in Elements.XML as well? After making your suggested change, I have same XML structure of ContentType tag both in Elements.XML and Schema.XML

[image: CT] https://user-images.githubusercontent.com/8166231/56035379-03636080-5cf8-11e9-9718-f0aa2d2c20fb.jpg

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SharePoint/sp-dev-docs/issues/1518#issuecomment-482546394, or mute the thread https://github.com/notifications/unsubscribe-auth/AWXKZdRb-zlGG5BeUEMKBtuOoczpT2vyks5vgHPngaJpZM4S3IAZ .

justdevelopment avatar Apr 12 '19 12:04 justdevelopment

Thank you. It worked. If anyone faces this situation, I will post my complete solution in a while and provide the link here.

mjmohitjoshi avatar Apr 13 '19 09:04 mjmohitjoshi

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

ghost avatar Nov 04 '20 12:11 ghost