In order to capture email metadata on SharePoint while saving emails using the Outlook Add-In you must create the relevant fields in SharePoint/M365. The fields can be created by the site Owners manually or by a SharePoint administrator using PowerShell scripts – it is recommended to use this method over the manual process.
After the fields have been created you will need to add them to relevant content types or directly to document libraries.
Note: you should consider creating these fields within a Content Type Publishing site. This will ensure that all sites can use these columns and creating them individually within each site is not required.
Note: we strongly recommend that you test these scripts in a development environment before running in production. This option involves using PowerShell and should be executed by someone who is comfortable using scripts and is a SharePoint site administrator.
Create Site Columns
Update the $Url and $contentTypes variables in the script below
- $Url should be the target SharePoint where the fields are to be created
- $contentTypes should be a comma separated values of Content Type names that you want to update for the field association
Start PowerShell and run the below script
function Set-SPOKEFields {
param (
[Parameter(Mandatory=$true,Position=1)]
[string[]]$Fields
)
try {
$oFields = Get-PnPField
foreach($field in $Fields) {
$existingField = $oFields | Where-Object {$_.InternalName -eq $field}
if($existingField -ne $NULL) {
Write-host "Site Column $field already exists!" -ForegroundColor Yellow
}
else {
$displayName = $field -replace "Em","Email "
$guid = Get-FieldID -FieldName $field
if ($field -eq "EmDate") {
$FieldSchema = "<Field ID='$guid' Type='DateTime' DisplayName='$displayName' Name='$field' ShowInNewForm='FALSE' ShowInEditForm='FALSE' Group='Konnect eMail Fields' />"
}
elseif ($field -in @(
"EmFrom","EmSubject","EmAttachmentCount","EmSensitivity",
"EmTransferAction","EmConversationTopic","EmConversationIndex","EmConversationId"
)) {
$FieldSchema = "<Field ID='$guid' Type='Text' DisplayName='$displayName' Name='$field' ShowInNewForm='FALSE' ShowInEditForm='FALSE' Group='Konnect eMail Fields' />"
}
else {
$FieldSchema = "<Field ID='$guid' Type='Note' DisplayName='$displayName' Name='$field' ShowInNewForm='FALSE' ShowInEditForm='FALSE' Group='Konnect eMail Fields' />"
}
Add-PnPFieldFromXml -FieldXml $FieldSchema
Write-host "Site Column Created Successfully!" -ForegroundColor Green
}
}
}
catch [Net.WebException] {
Write-Host "$Url failed to connect to the site. $($_.Exception.Message)" -ForegroundColor Red
}
}
function Get-FieldID {
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$FieldName
)
$guid = switch ($FieldName) {
"EmDate" {"b1f75b72-daed-4963-a8b0-99b598205eb0"}
"EmTo" {"1abc7201-880b-4802-912a-32669f4cda6e"}
"EmFrom" {"5797777c-2cfe-4b9e-8638-298c36f1a3d4"}
"EmCC" {"31399494-ca4d-4da9-bdb6-f452e56c4b12"}
"EmBCC" {"88511fc1-04be-4a08-bc4d-122c43541447"}
"EmSubject" {"2dde6173-4ffc-430d-a8bd-97de57cb432b"}
"EmBody" {"c6c37ebd-bae0-4c89-b6ef-5d93dd917d8f"}
"EmConversationTopic" {"0443e054-e14a-40c1-89cc-fcd1e63d6286"}
"EmConversationIndex" {"9bf6a98c-bae4-40d5-ad9c-722870d25e6d"}
"EmConversationId" {"59e4db4e-f328-4028-bade-95d33106e8bc"}
"EmAttachmentCount" {"d48beaf0-2cac-4628-8dd4-924129914886"}
"EmAttachment" {"8bd27213-794b-40ac-8542-277cdb016985"}
"EmSensitivity" {"b2ca25c8-6704-4591-b363-c5fd6dbd45b9"}
"EmTransferAction" {"ba53ff39-2fc3-4b20-8a1e-2005a5e580d2"}
"EmURLs" {"a458d01f-2bd7-4776-9f49-3b3180b446d5"}
"EmKeywords" {"bc7d058f-ead1-41d2-83a9-a7f7178d6cc8"}
default {""}
}
return $guid
}
function Add-FieldToLists {
param (
[Parameter(Mandatory=$true,Position=1)]
[string[]]$Fields
)
$docLibraries = Get-PnPList | Where-Object {$_.BaseTemplate -eq 101 -and $_.Hidden -eq $false}
foreach($docLibrary in $docLibraries) {
$confirm = Read-Host "Do you want to add fields to '$($docLibrary.Title)'? (y/n)"
if($confirm -eq "y") {
foreach($field in $Fields) {
$oField = Get-PnPField -List $docLibrary.Title | Where-Object {$_.InternalName -eq $field}
if($oField -ne $NULL) {
Write-host "Field $field already exists!" -ForegroundColor Yellow
}
else {
Write-host "Adding Field $field to $($docLibrary.Title)..." -ForegroundColor Yellow
Add-PnPField -List $docLibrary.Title -Field $field
Write-host "Field added to $($docLibrary.Title)!" -ForegroundColor Green
}
}
}
}
}
function Add-FieldToContentTypes {
param (
[Parameter(Mandatory=$true,Position=1)]
[string[]]$Fields,
[Parameter(Mandatory=$true,Position=2)]
[string[]]$ContentTypes
)
foreach($ContentType in $ContentTypes) {
$ct = Get-PnPContentType -Identity $ContentType
$confirm = Read-Host "Do you want to add fields to content type '$ContentType'? (y/n)"
if($confirm -eq "y") {
foreach($field in $Fields) {
Write-host "Adding Field $field to Content Type $ContentType..." -ForegroundColor Yellow
Add-PnPFieldToContentType -Field $field -ContentType $ct
Write-host "Field added to $ContentType!" -ForegroundColor Green
}
}
}
}
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Install-Module PnP.PowerShell -RequiredVersion 1.12.0 -Scope CurrentUser -Verbose -Force
Import-Module PnP.PowerShell -Scope Local -WarningAction SilentlyContinue
$Url = "https://tenent-name.sharepoint.com/sites/site-name"
$fields = "EmDate","EmTo","EmFrom","EmCC","EmSubject","EmBody","EmConversationTopic","EmConversationIndex","EmConversationId","EmAttachmentCount","EmAttachment","EmBCC","EmSensitivity","EmTransferAction"
$contentTypes = "Document","Document Set"
Connect-PnPOnline -Url $Url -Interactive
Set-SPOKEFields -Fields $fields
Add Columns to Content Types
Skip this step if you do NOT use content types on the SharePoint site.
- Update the “$contentTypes” variable with the names of content types and run the below code
Add Columns to Document Library
Skip this step if you have added the Konnect eMail fields to content types directly in the above steps.
- Run the below code and select the libraries you want to update individually
