Installing webpart to SharePoint Online via sppkg, how to programmatically change configuration parameters at install time?

Dylan Nicholson 1 Reputation point
2024-01-19T03:18:29.8733333+00:00

If we have a webpart that needs particular configuration parameters that will change with each installation (e.g. the AAD/Entra tenant-id), and we need to be able to automatically configure a webpart added to a Sharepoint tenancy via the App Catalog, how can we programmatically set these configuration parameters so that each time the webpart is added to a page it has the right values?
The only thing I can think of that would work is to unpack the sppkg, update the files containing the configuration values (there are a few), and repackage again, but that's pretty ugly and from experience can cause odd errors. I suppose in principle it's possible for the web part to somehow go off and fetch those configuration values from somewhere in SP itself where the installer puts them? But what if it had been added to teams etc.?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,398 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,563 questions
0 comments No comments
{count} votes