0

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

1 Answer 1

0

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

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

Also there is similar question in SharePoint Exchange here

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.
5
  • Sorry, SharePoint Hosted Apps do not support Event Receivers. Commented Apr 11, 2017 at 7:09
  • Ok, I totally misread your question, please see update.
    – bkk
    Commented Apr 11, 2017 at 7:26
  • thank you for reply, however, question is how to execute some code (which will create columns) only once i.e. when App is installed or first time user accessed it. Commented Apr 11, 2017 at 7:37
  • 1
    SharePoint hosted add-ins do not support event receivers like SharePoint list item create/update event. However, they do support app install/uninstall/upgrade events. You can write a provider hosted component for just this purpose, rest of the functionality can be in the SharePoint hosted pages of the app.
    – Prakash
    Commented Apr 11, 2017 at 8:02
  • As Prakash said, it should fine to use separate add-in for managing provisioning. Look for my second update for more on this.
    – bkk
    Commented Apr 11, 2017 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.