top of page

Configure Approvals in libraries - THE workaround

Writer: Kasper Larsen
Kasper Larsen
7 hours ago
2 min read

The Out of the box approvals is in many cases sufficient for basic approval flows ( otherwise you have to create your own PowerAutomate flow ) and the configuration of the feature is pretty easy.

So now the Organization is requesting that we set up the Approvals configuration in the Site/Teams provisioning, which should be a piece of cake, just use the PowerShell CMD and we are done.


Unfortunately Microsoft has decided not to create an API for this, again !!!.


<rant>

In my honest opinion Microsoft is in many ways a dysfunctional orginazation, and the focus on short term KPIs and the constant rotation of people doesn't help neither.
Likewise, it seems that part of the SharePoint team at Microsoft consider SharePoint as a SAAS solution rather than a platform, an thus have no focus on extensibiblity and automation.

</rant>


I have reached out to the Feature PM asking why they release a feature without a API but it seems like the feature plan never contained anything about an API.





The best alternative is a site template verb "enableApprovals", which can be used in a site script to create a library and configure that Approvals for that library, so it is a one-shot "solution", rather than a proper API.


Normally we create SharePoint content via a PnP Provisioning template or raw PnP.PowerShell so using a site script will require us to rework the existing flow as the library that needs Approvals enabled will have to be created via the site script now.



The current implementation is wrapped in an Azure Function using PnP.PowerShell and basically a wrapper around Invoke-PnPSPRestMethod:

$response = Invoke-PnPSPRestMethod -Method Post -Url $endpoint -Content $restBody -ContentType 'application/json;odata=nometadata' -Connection $Connection -ErrorAction Stop


The REST body could look like below.


We are creating a "Project Documents" library, enable Approvals, adds default approvers, and finally sets DefaultRequireAll and CanOverwrite to false.



{

"script": {

"$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",

"actions": [

{

"verb": "createSPList",

"listName": "Project Documents",

"templateType": 101,

"subactions": [

{

"verb": "enableApprovals"

},

{

"verb": "addRules",

"quicksteps": [

{

"condition": "true",

"title": "Default approvers rule",

"actionType": "20001",

"ruleTemplateId": "bf2c069a-2db8-4a48-9dc6-b62dfd17f80d",

"actionParams": {

"Approvers": [

[

{

"name": "Bob Smith",

"providerName": "Tenant",

"entityType": 0,

"isResolved": true,

"aadObjectId": "11111111-2222-3333-4444-555555555555",

"principalType": 1

}

]

],

"DefaultRequireAll": "false",

"CanOverwrite": "false"

}

}

]

}

]

}

],

"bindata": {},

"version": 1

}

}


This actally works, but I am still baffled why we have to jump through all those hoops and spend hours on creating a workaround for something that Microsoft SHOULD provide an API for.

 
 
 

Comments


30103817

  • Twitter
  • LinkedIn

©2023 by M365thinking. Proudly created with Wix.com

bottom of page