1

I've searched for hours to find an answer, but wasn't able to find anything I could use for my case.

I'm using PnP to create a new list on my site but I would like to use an already existing Content Type to create the list from. Is it even possible?

This is how I create the list: enter image description here

Thanks in advance

  • 1
    can you share some code snippet showing us how you are creating a list ? You can also post a documentation link if it you are referring to it – Gautam Sheth Aug 30 '18 at 12:32
  • Thanks for the reply. I've added a code snippet to the description. – fkgdmk Aug 30 '18 at 12:44
2

You can do it after you've created the list.

First you need to have the CT ID

pnp.sp.site.rootWeb.contentTypes.select("StringId,Name").get()
 .then((cts: any) => {
   cts.forEach(ct => {
     if (ct.Name === ctName) {
       return resolve(ct.StringId);
     }
   });

   // no matching CTs found, don't add anything
   resolve("");
 })

So basically something like

pnp.sp.web.lists.add(listName, "", baseTemplate, true) // true here to allow CTs
    .then((lar: ListAddResult) => {
        lar.list.contentTypes.addAvailableContentType(ctId)
    });
  • Glad I could help! Please remember to mark question as answered. – Jussi Palo Aug 30 '18 at 13:11

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.