pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
905 stars 317 forks source link

Unable to set default Content Type using spo list contenttype default set #6222

Closed louderthanloud123 closed 1 month ago

louderthanloud123 commented 1 month ago

Priority

(Medium) I'm annoyed but I'll live

Description

HI,

I am trying to run a sequence of commands to add a content type to a library, set it as default, then remove the other types. I've successfully managed to add the content type using the command:

m365 spo list contenttype add --webUrl $url --listTitle $title --id "0x0101006D0B837F74DB2C42B416401683C1AE56"

I then run the command:

m365 spo list contenttype default set --webUrl $url --listTitle $title --contentTypeId "0x0101006D0B837F74DB2C42B416401683C1AE56"

I then get an an error: Error: Content type 0x0101006D0B837F74DB2C42B416401683C1AE56 missing in the list. Add the content type to the list first and try again.

If I run the add content type command again, I get: Error: A duplicate content type "CONTENTYPE NAME" was found.

So it seems that the Content Type is being added, but the default set command is unable to see that it has been.

In the GUI I can see that it is indeed there and I am able to set as default.

Steps to reproduce

Create a new content type, note the ID Run command m365 spo list contenttype add --webUrl $url --listTitle $title --id "CONTENT TYPE ID"

Then run m365 spo list contenttype default set --webUrl $url --listTitle $title --contentTypeId "CONTENT TYPE ID"

Receive message: Error: Content type CONTENT TYPE ID missing in the list. Add the content type to the list first and try again

Expected results

Expect that the specified content type is made the default

Actual results

error: Error: Content type CONTENT TYPE ID missing in the list. Add the content type to the list first and try again

Diagnostics

Executing command spo list contenttype default set with options {"options":{"webUrl":"https://sitename.sharepoint.com/sites/demo","listTitle":"Test1","contentTypeId":"0x0101006D0B837F74DB2C42B416401683C1AE56","debug":true,"output":"json"}} Executing command as 'Username', appId: AppID, tenantId: TenantID Retrieving content type order... Existing access token BEARERTOKEN still valid. Returning... Request: { "url": "https://sitename.sharepoint.com/sites/demo/_api/web/lists/getByTitle('Test1')/RootFolder?$select=ContentTypeOrder,UniqueContentTypeOrder", "method": "get", "headers": { "Accept": "application/json;odata=nometadata", "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/8.1.0-beta.bf59841", "accept-encoding": "gzip, deflate", "X-ClientService-ClientTag": "M365CLI:8.1.0-beta.bf59841", "authorization": "Bearer BEARERTOKEN" }, "responseType": "json", "decompress": true } Response: { "url": "https://sitename.sharepoint.com/sites/demo/_api/web/lists/getByTitle('Test1')/RootFolder?$select=ContentTypeOrder,UniqueContentTypeOrder", "status": 200, "statusText": "OK", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Tue, 23 Jul 2024 08:00:52 GMT", "last-modified": "Wed, 07 Aug 2024 08:00:52 GMT", "vary": "Origin,Accept-Encoding", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,1573888,14,7,360135,0,1573888,3", "x-sharepointhealthscore": "0", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "25", "sprequestduration": "26", "x-aspnet-version": "4.0.30319", "x-databoundary": "EU", "x-1dscollectorurl": "https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://eu-mobile.events.data.microsoft.com/Collector/3.0", "sprequestguid": "7ce043a1-e007-9000-5048-a8254f833e83", "request-id": "7ce043a1-e007-9000-5048-a8254f833e83", "ms-cv": "oUPgfAfgAJBQSKglT4M+gw.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com teams.cloud.microsoft .office365.com goals.cloud.microsoft .powerapps.com .powerbi.com .yammer.com engage.cloud.microsoft word.cloud.microsoft excel.cloud.microsoft powerpoint.cloud.microsoft .officeapps.live.com .office.com .microsoft365.com .stream.azure-test.net .microsoftstream.com .dynamics.com .microsoft.com onedrive.live.com .onedrive.live.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.25124", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 588F7DFBD4604293AC37D56EEDAEB131 Ref B: LON601060106040 Ref C: 2024-08-07T08:00:52Z", "date": "Wed, 07 Aug 2024 08:00:52 GMT" }, "data": { "ContentTypeOrder": [ { "StringValue": "0x010100AF2AEED718513D46BC03C94985C80762" }, { "StringValue": "0x0101006D0B837F74DB2C42B416401683C1AE5600186D8BFCE3FBA844A0D0C45FE11CFA8C" } ], "UniqueContentTypeOrder": [ { "StringValue": "0x010100AF2AEED718513D46BC03C94985C80762" }, { "StringValue": "0x0101006D0B837F74DB2C42B416401683C1AE5600186D8BFCE3FBA844A0D0C45FE11CFA8C" } ] } } Using unique content type order Content type 0x0101006D0B837F74DB2C42B416401683C1AE56 is not visible in the list Retrieving list content types... Existing access token BEARERTOKEN still valid. Returning... Request: { "url": "https://sitename.sharepoint.com/sites/demo/_api/web/lists/getByTitle('Test1')/ContentTypes?$select=Id", "method": "get", "headers": { "Accept": "application/json;odata=nometadata", "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/8.1.0-beta.bf59841", "accept-encoding": "gzip, deflate", "X-ClientService-ClientTag": "M365CLI:8.1.0-beta.bf59841", "authorization": "Bearer BEARERTOKEN" }, "responseType": "json", "decompress": true } Response: { "url": "https://sitename.sharepoint.com/sites/demo/_api/web/lists/getByTitle('Test1')/ContentTypes?$select=Id", "status": 200, "statusText": "OK", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Tue, 23 Jul 2024 08:00:52 GMT", "last-modified": "Wed, 07 Aug 2024 08:00:52 GMT", "vary": "Origin,Accept-Encoding", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,1573888,0,30,360194,0,1391712,3", "x-sharepointhealthscore": "2", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "20", "sprequestduration": "20", "x-aspnet-version": "4.0.30319", "x-databoundary": "EU", "x-1dscollectorurl": "https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://eu-mobile.events.data.microsoft.com/Collector/3.0", "sprequestguid": "7ce043a1-100d-9000-8cbb-4c7217159770", "request-id": "7ce043a1-100d-9000-8cbb-4c7217159770", "ms-cv": "oUPgfA0QAJCMu0xyFxWXcA.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com teams.cloud.microsoft .office365.com goals.cloud.microsoft .powerapps.com .powerbi.com .yammer.com engage.cloud.microsoft word.cloud.microsoft excel.cloud.microsoft powerpoint.cloud.microsoft .officeapps.live.com .office.com .microsoft365.com .stream.azure-test.net .microsoftstream.com .dynamics.com .microsoft.com onedrive.live.com .onedrive.live.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.25124", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 06C4C10D6D6B4FBD82F490118D3EE039 Ref B: LON601060106040 Ref C: 2024-08-07T08:00:52Z", "date": "Wed, 07 Aug 2024 08:00:52 GMT" }, "data": { "value": [ { "Id": { "StringValue": "0x010100AF2AEED718513D46BC03C94985C80762" } }, { "Id": { "StringValue": "0x0101006D0B837F74DB2C42B416401683C1AE5600186D8BFCE3FBA844A0D0C45FE11CFA8C" } }, { "Id": { "StringValue": "0x012000648C02BD8D60AC47B8888FA3786DF836" } } ] } }

Timings: api: 343.9123ms core: 10.7591ms command: 387.0574ms options: 0.2185ms total: 399.2533ms validation: 0.3178ms Error: Content type 0x0101006D0B837F74DB2C42B416401683C1AE56 missing in the list. Add the content type to the list first and try again.

CLI for Microsoft 365 version

v8.1.0-beta.bf59841

nodejs version

v20.15.1

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

{ "os": { "platform": "win32", "version": "Windows 10 Enterprise", "release": "10.0.19045" }, "cliVersion": "8.1.0-beta.bf59841", "nodeVersion": "v20.15.1", "cliAadAppId": "APPID", "cliAadAppTenant": "common", "authMode": "Browser", "cliEnvironment": "", "cliConfig": {}, "roles": [], "scopes": { "https://graph.microsoft.com": [ "AllSites.FullControl", "AppCatalog.ReadWrite.All", "AuditLog.Read.All", "Bookings.Read.All", "Calendars.Read", "ChannelMember.ReadWrite.All", "ChannelMessage.Read.All", "ChannelMessage.Send", "ChannelSettings.ReadWrite.All", "Chat.Read", "Chat.ReadWrite", "Directory.AccessAsUser.All", "Directory.ReadWrite.All", "ExternalConnection.ReadWrite.All", "ExternalItem.ReadWrite.All", "Group.ReadWrite.All", "IdentityProvider.ReadWrite.All", "InformationProtectionPolicy.Read", "Mail.Read.Shared", "Mail.ReadWrite", "Mail.Send", "Notes.Read.All", "OnlineMeetingArtifact.Read.All", "OnlineMeetings.ReadWrite", "OnlineMeetingTranscript.Read.All", "PeopleSettings.ReadWrite.All", "Place.Read.All", "Policy.Read.All", "RecordsManagement.ReadWrite.All", "Reports.Read.All", "RoleAssignmentSchedule.ReadWrite.Directory", "RoleEligibilitySchedule.Read.Directory", "SecurityEvents.Read.All", "ServiceHealth.Read.All", "ServiceMessage.Read.All", "ServiceMessageViewpoint.Write", "Sites.Read.All", "Tasks.ReadWrite", "Team.Create", "TeamMember.ReadWrite.All", "TeamsAppInstallation.ReadWriteForUser", "TeamSettings.ReadWrite.All", "TeamsTab.ReadWrite.All", "TermStore.ReadWrite.All", "User.Invite.All", "User.ReadWrite.All", "profile", "openid", "email" ], "https://nrshealthcare.sharepoint.com": [ "AllSites.FullControl", "AppCatalog.ReadWrite.All", "AuditLog.Read.All", "Bookings.Read.All", "Calendars.Read", "ChannelMember.ReadWrite.All", "ChannelMessage.Read.All", "ChannelMessage.Send", "ChannelSettings.ReadWrite.All", "Chat.Read", "Chat.ReadWrite", "Directory.AccessAsUser.All", "Directory.ReadWrite.All", "ExternalConnection.ReadWrite.All", "ExternalItem.ReadWrite.All", "Group.ReadWrite.All", "IdentityProvider.ReadWrite.All", "InformationProtectionPolicy.Read", "Mail.Read.Shared", "Mail.ReadWrite", "Mail.Send", "Notes.Read.All", "OnlineMeetingArtifact.Read.All", "OnlineMeetings.ReadWrite", "OnlineMeetingTranscript.Read.All", "PeopleSettings.ReadWrite.All", "Place.Read.All", "Policy.Read.All", "RecordsManagement.ReadWrite.All", "Reports.Read.All", "RoleAssignmentSchedule.ReadWrite.Directory", "RoleEligibilitySchedule.Read.Directory", "SecurityEvents.Read.All", "ServiceHealth.Read.All", "ServiceMessage.Read.All", "ServiceMessageViewpoint.Write", "Sites.Read.All", "Tasks.ReadWrite", "Team.Create", "TeamMember.ReadWrite.All", "TeamsAppInstallation.ReadWriteForUser", "TeamSettings.ReadWrite.All", "TeamsTab.ReadWrite.All", "TermStore.ReadWrite.All", "User.Invite.All", "User.ReadWrite.All" ] } }

Additional Info

No response

milanholemans commented 1 month ago

Hi @louderthanloud123 Thank you for logging the issue above. From what I can see, is it possible that you are using the wrong content type ID when using spo list contenttype default set? When you add a content type to a list, the ID from the content type is not the same as the ID of the content type defined in your site. When you use spo list contenttype add, you should use the ID from the output in the spo list contenttype default set command. Could you try this approach?

louderthanloud123 commented 1 month ago

Hi,

Thanks for the response, I'm struggling to understand? The spo list contenttype add command works, and accepts the ID from the content type definition in SharePoint admin centre and I've verified that it does add it.

Are you saying that this generates another ID somewhere that I need to use to set the default? I guess that may explain the --contentTypeId for the default set and the --id for the add and if that's the case, how do I get this other Id?

milanholemans commented 1 month ago

Sorry if my last message was a bit unclear. Let me explain with an example.

When you have a content type in your SharePoint site with ID 0x0100A33D9AD9805788419BDAAC2CCB37509F, and you add it to a SharePoint list, the content type added to your list will have a content type ID that looks like this: 0x0100A33D9AD9805788419BDAAC2CCB37509F006454F8883E8BA648A632E5ACB47CAD9B. As you can see, the list content type has a longer ID than the site content type. The list content type ID also starts with the ID of the site content type. What I'm trying to say is, that when you use content types in a SharePoint list, the list content type has a different (longer) ID than the site content type you've used.

Site content type ID:   0x0100A33D9AD9805788419BDAAC2CCB37509F
List content type ID:   0x0100A33D9AD9805788419BDAAC2CCB37509F006454F8883E8BA648A632E5ACB47CAD9B

So what your script should do, is something like this (assuming you are using PowerShell):

$contentType = m365 spo list contenttype add --webUrl $url --listTitle $title --id "0x0101006D0B837F74DB2C42B416401683C1AE56" | ConvertFrom-Json
m365 spo list contenttype default set --webUrl $url --listTitle $title --contentTypeId $contentType.StringId
louderthanloud123 commented 1 month ago

Aha, gotcha, I think somewhere deep in my brain I remember now reading somewhere that it appends to the list ID!

I am indeed using Powershell, and I've just tried that code you provided and boom, it works! Legend! Thank you!

milanholemans commented 1 month ago

Glad it works! 😊