Question:

How to do one time configuration of SharePoint Hosted Add-in?

Gabriella: 5 days ago

We need to create a few fields after installation of SharePoint Hosted Add-in. What would be the preferred way to achieve this?

Answer:
Addison: 5 days ago

Note - Assuming you want the new fields to be created under the host web.

Use add-in event receiver along with remote provisioning to add the new fields during add in install or upgrade.

For more on add-in event receivers read Create an add-in event receiver in SharePoint Add-ins (https://msdn.microsoft.com/en-us/library/office/jj220052.aspx)

Once you have the client context for the Host Web you can use the CSOM code to create fields in the site as usual.

Few consideration, since the implementation is using code and not features -

  • Handling clean up on add-in uninstall is your responsibility.
  • Handling upgrade scenarios
  • Add-in Permission required

UPDATE 1 Read the blog by Chris O'Brien SP2013 host web apps: provisioning fields and content types (http://www.sharepointnutsandbolts.com/2013/06/sp2013-host-web-apps-provisioning.html)

Also there is similar question in SharePoint Exchange here (https://sharepoint.stackexchange.com/questions/129318/sharepoint-hosted-app-create-a-content-type-in-host-web)

UPDATE 2 There two possible approaches that I can think off, when it comes to being able to make changes to host web only once.

  • Create a companion add-in SharePoint Hosted or Provider Hosted for managing provisioning.
  • Use custom configuration list under Add-in Web and track status of custom provisioning in the host web.