Add-SPOSiteDesignTask : Operation is not valid due to the current state of the object.

Copper Contributor

I have created site design with two site scripts. applied using below command

$Sitedesignout1=Add-SPOSiteDesign -Title "Site Design 2" -WebTemplate "68" -SiteScripts $result1.Id,$result2.Id -Description "Site Desin Sample"

 

But after try to apply Site design using below code throwing an Operation is not valid due to the current state of the object error

 

$adminSiteUrl = "https://myadmin-admin.sharepoint.com"

$siteUrl = "https:// myadmin.sharepoint.com/sites/PracticeSiteDesign"

$siteDesignId = "04d0e647-5912-4ef7-8069-9186cebb2192"

 

Connect-SPOService $adminSiteUrl

$task = Add-SPOSiteDesignTask -SiteDesignId $siteDesignId -WebUrl $siteUrl

Add-SPOSiteDesignTask : Operation is not valid due to the current state of the object.

At line:6 char:9

+ $task = Add-SPOSiteDesignTask -SiteDesignId $siteDesignId -WebUrl $si ...

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Add-SPOSiteDesignTask], ServerException

    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.AddSPOSiteDesignTask

 

5 Replies

@Dinesh Bhat I've historically encountered this same error, albeit not with the SPOSiteDesignTask cmdlet. Have you ensured that the site that you're trying to interact with is not being edited by anybody else at the time that the command is running, and that any pending changes have been published? Have you also encountered this same issue with different site designs, or is it only this site design which has been presenting issues?

 

Hope this helps!

@rowanhucklebridge , Thanks for the reply. I have created new site without any additional content. So there is no pending changes and I am the only person having access to the site. 

 

if I create site design for each site script its working good. But only problem I need register multiple site design to tenant.

 

if I combine site script and registered as one site design, throwing below error.

 

Please share your thought 

 

 

@Dinesh Bhat I'm not sure how much help I can be here. Whenever I've previously received the same error message that you've been receiving - "Operation is not valid due of the current state of the object" - it usually means that whatever I am attempting to edit or modify cannot currently be modified, for instance if it is already undergoing edits or changes. So whilst I don't think I'm able to suggest a fix for you, I might be able to help diagnose where things are going wrong.

 

To this end, do you have multiple site scripts interact with the same sections/functions/areas? Could this be where the issue is coming from?

@rowanhucklebridge 

Thanks, each list is separate there is no connection. I have tried with 7 list with 2 site scripts it works, if i add one more site script below error throwing 

We have large site with more than 30 list and library. So we have split into 4 site scripts due to limit of 100000 characters. After we have added 4 site scripts into site using below code

Add-SPOSiteDesign `
-Title "My customer tracking" `
-WebTemplate "64" `
-SiteScripts script1.id,script2.id,script3.id,script4.id `
-Description "Tracks key customer data in a list" `
-PreviewImageUrl "https://contoso.sharepoint.com/SiteAssets/site-preview.png" `
-PreviewImageAltText "site preview"

 

After when we try to apply Add-SPOSiteDesignTask throwing below error 

 

"Operation is not valid due to the current state of the object"  any idea? how to resolve or root cause

 

@Dinesh Bhat 

 

Hi Dinesh, did you ever find a resolution for this issue? I am getting the same thing, I can split the scripts into  more site designs an it will work , but then I need to trigger multiple site designs. the only other option is to have azure run the scripts, but that involves a premium license for HTTP requests in flow. or setting up a datagateway server on premise to run the script. 

 

 

Cheers

**update**

I am getting the same issue running via Azure runbook as well.  the only options i will be left with is adding the site design task via RestApi if i want to keep the large site design. or split to many site designs( as that works). Any help with this would be appreciated.

 

cheers