How to run this Jsom code ?

developer sp1 461 Reputation points
2020-11-11T08:40:16.637+00:00

I was looking for ways I can automatically change the content type of my files inside SharePoint online.
I'm not sure how the code is supposed to work. Added a Webpart, scripteditor on my document library.

At the part in the code where is says contenttypeId, I've pasted the content type id I want the files to be change to.

Nothing is happening. Not sure how the code is supposed to work.

Here is the code:

39023-snipaste-2020-11-11-16-39-23.png

Please help on this ?

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,606 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerryzy 10,571 Reputation points
    2020-11-12T08:47:39.23+00:00

    Hi @developer sp1 ,

    Before running the code snippet, need to enable the Content Type Management for the library and add the Content Type needed in library settings,for example, I want to set Content Type "Images" for Item 7 which is an image:

    39256-1.png

    Add the code using Script Editor Web Part:

    39312-2.png

    39285-3.png

    Will set the content type successfully:

    39331-4.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.