Klevr Product Documentation logo

SharePoint Document Attachments

This article describes the procedure for configuring SharePoint Attachments on Klevr Portal.

This article describes the procedure for configuring SharePoint Attachments on Klevr Portal. There is quite a bit of configuration that needs to be completed before any of the integration will work. Please follow the steps closely. The infrastructure pipeline may provision some of these steps for you, but it is worth checking everything is in place.

The following configrations are required:

  • SharePoint Integration in Dynamics. Set to Server Side Sync. Not based on an entity hierarchy. We have not tested the hierarchical configuration method, so you are welcome to try it in a non critical environmnet and test it and let us know of any issues, but currently we only support a flat hierarchy. Ensure you have SharePoint integration enabled for the target entity, and have run through the wizard to create the initial document library for the entity.
  • Portal Access to SharePoint. SharePoint only works with a certificate, which complicates things. To store the certificate, we use KeyVault. So a few things need to happen here, described in detail below. The App Registration used by the portal for Dynamics access (or a different one if you prefer) need be be granted SharePoint API permissions. Then a Certificate needs to be generated and uploaded to the App Registration. This Certificate then needs to be stored in a keyvault. The Web Site needs to be given a Managed Identity, and the Identity needs to be granted access to read certificates from the keyvault. The relevant settings and URL's then need to be updated in your pipeline variables and deployed to your portal. You may also need a setting called 'WEBSITE_LOAD_CERTIFICATES=1'
  • SharePoint Attachment Configuration in Umbraco. This is the easy bit where you simply add the attachment control to your Dynamics 2.0 Page and fill in the details.

SharePoint Integration in Dynamics

1
Enable SharePoint Integration on the entity

Ensure your target entities that you want attachments to be uploaded to is enabled for SharePoint Integration. This can be done in make.powerapps.com under the properties for the respective table.

2
Enable SharePoint Server Side Sync

In Dynamics, Under the advanced settings, navigate to Document Settings. Enable SharePoint Server Side Sync if it has not been done yet.

3
Run the SharePoint site setup wizard

Run the wizrd and enter the root URL of your SharePoint site and click next.

4
Select a flat hierarchy

Ensure you do not select Hierarchical based on entity, and click next.

5
Confirm document libraries are created

Wait for all the document Libraries to be created. Ensure your target entity is in the list and has a document library created for it.

6
Create an initial document location

Create as least 1 record of this type in Dynamics and click on the documents tab to create a document location. This will create the neccesary parental locations required for other records. You can delete this record now. The portal can attach files to a newly created record and will create the initial document locations automatically if they don't exist, but it does not create the parent document locations, hence why this step is required.

7
Repeat for other entities

Repeat for each entity that you intend to use SharePoint attachments for.

Portal Access to SharePoint

The Infrastructure pipeline will take care of most of these steps for you, but they are explained here for manual troubleshooting.

1
Add SharePoint API access to the app registration

To access SP, you need to use an app registration. You can use the same app registration that is used to access Dynamics, or you can create a specific one. Either way, you need to add the SharePoint API access to the app registration. Locate the App Registration you will be using (e.g. the one used to access dynamics). Under the API Permissions section, add Full control to Sharepoint, as per screenshot below:

Portal Access to SharePoint (1)

Portal Access to SharePoint (1)
2
Copy the KeyVault URL

Ensure you have a keyvault created as part of the infra. Copy the URL of the keyvault, it will be required in your pipeline Variables.

3
Generate a certificate in the KeyVault

Under certificates and secrets in the keyvault, generate a new certificate. Give it a name like SPAccess (This is also required in the pipeline variables).

4
Make the certificate self-signed

Make it self signed, and give it a validity period. If it expires it will have to be generated, so I suggest making it like 10 years.

5
Upload the certificate to the app registration

Download the certificate in CER format. Go back to the app registration above, and upload this on the App Registration screen, Under Certificates and Secrets.

6
Confirm the Managed Identity is enabled

Go to the App Service (website) and check that 'System Assigned Managed Identity' is switched on on the Portal Site. Copy the principal id.

7
Grant the Managed Identity access to the KeyVault

Grant access to read certificates on the keyvault to this App Service Principal. To do this, go to the keyvault, Access Control, Role Assignments and add an assignment. Select Key Valut Certificuate User in the role. Select 'Managed Identity' in the Members, and select the App Service Manage Identity (it would have the name of the web site). This process might differ slightly depending on whether your keyvault was configured for Role Based Access or not.

8
Configure the library variables

Now configure the library variables according to the following table:

NameValue
Klevr.SharePointCertificateNameName of your certificate in the KeyVault (e.g. SPAccess as configured above).
Klevr.KeyVaultUrlURL of your KeyVault. Can be copied from the overview page of the keyvault.
Klevr.SharePointDomainThe domain Sharepoint is in. This is typically the login domain for the csutomer, e.g. walkerscott.co or customer.co.nz.
Klevr.SharePointAppIdIf you used the same App ID that you use for the portal to get access to Dynamics, then you can leave this blank. This is the app id that you uploaded the certificate to and assigned the API access to
Klevr.SharePointTenantIdThis is the Azure Tenant ID for the tenant that SharePoint is hosted in
9
Enable certificate loading on the web app

Lastly, you may need to configure the following Environment Variable on your site. In the Azure Portal on your web site app service, go to "Settings" -> "Environment Variables". Click on New. the name of the setting is 'WEBSITE_LOAD_CERTIFICATES' and the value is 1. Leave deployment setting unchecked and click ok.

SharePoint Attachment Configuration in Umbraco

Now for the fun part. You can add a SharePoint Attachment block to a Dynamics Form 2.0 page in Umbraco. It is similar to the Azure Attachment block, but there are a few key differences:

The CE / SharePoint integration does not allow us to add custom fields like document description or a custom type to it, so you will notice these are not available options. However, we do have a trick up our sleeve. You can use the "Subfolder" property to specify a folder that the files will be stored in, and you can add multiple SharePoint attachment sections to a single form, each with their own subfolder. This way you could effectively mimic a file type selection by having a section for each, and saving them to different folders.

The CE / SharePoint integration does not create a CE record per attachment, and so permissions for attachments are derived from the current record you are on. You can specify the level of permission required on the base record for each action, for instance, you can prevent uploading or deleting of files if the user does not have write access, and prevent listing the files if the user does not have read access. Keep in mind that Deleting an attachment is not neccesarily linked to being able to delete the record, but rather to the ability to update a record, but you can configure it as per your needs and requirements.

You do not have to add a list section as you need to do with Azure Attachments, because we do not have a record in CE for each SharePoint File. The files are listed in the upload control itself. However, you do need to specify some buttons. Typically you would create 2 buttons, 1 for delete and 1 for download. The order, label, icon and css are up to you. The filter conditions do not work for these buttons, so you can ignore that. For the JavaScript you need to specify either **DeleteSPAttachment** or **DownloadSPAttachment**. You can also specify your own buttons with your own functions, although there isn't much API support currently to help you work with the file control. Let us know if you need anything here, so we can build the appropriate hooks for your javascript.

The 'Accept', 'Max File Size' and 'File Limit' works as expected, unless it doesn't, in which case, please log a bug 😄. You can use the 'image/*;capture=camera' setting to allow upload directly from a device camera, although browser support for this is limited, so test it first on the intended device(s).

User Permissions

SharePoint Attachments rely heavily on the permissions for the underlying record. As such there is no need (or indeed ability) to set up specific permissions in the Klevr Table Permssions section for SharePoint Attachments. Instead, you restrict the actions on attachments based on the permissions of the underlying record within the configuration of the SharePoint Attachment section on your page.

Last updated on