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
Ensure you do not select Hierarchical based on entity, and click next.
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.
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.
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.
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.
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).
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.
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.
Go to the App Service (website) and check that 'System Assigned Managed Identity' is switched on on the Portal Site. Copy the principal id.
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.
Now configure the library variables according to the following table:
| Name | Value |
|---|---|
| Klevr.SharePointCertificateName | Name of your certificate in the KeyVault (e.g. SPAccess as configured above). |
| Klevr.KeyVaultUrl | URL of your KeyVault. Can be copied from the overview page of the keyvault. |
| Klevr.SharePointDomain | The domain Sharepoint is in. This is typically the login domain for the csutomer, e.g. walkerscott.co or customer.co.nz. |
| Klevr.SharePointAppId | If 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.SharePointTenantId | This is the Azure Tenant ID for the tenant that SharePoint is hosted in |
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
