Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for GtResourceLoad list column #710

Merged
merged 12 commits into from
May 24, 2022
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Install/SiteScripts/*.txt
Install/InstallLog.txt
Install/Scripts/UpgradeSites_Log*
release/*
SharePointFramework/**/.vscode/launch.json
SharePointFramework/**/pnpm-lock.yaml
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Every change is marked with issue ID.
- Example: Trigger API's, Flows, Logic Apps, Azure Functions, etc...
- Improvements to styling, sorting and information messages for the Document Template Selector #711

### Fixed

- Fixed issue with resource allocation percentage not showing #610. NB: The script UpgradeAllSitesToLatest.ps1 needs to be run to fix the issue for old sites!

## 1.5.0 - 01.04.2022

### Added
Expand Down
10 changes: 5 additions & 5 deletions Install/Scripts/PostInstallUpgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ if ($null -ne $LastInstall) {
Write-Host "[INFO] In version v1.2.7 we added 'Prosjekttidslinje' to the top navigation. Adding this navigation item now as part of the upgrade"
Add-PnPNavigationNode -Location TopNavigationBar -Title "Prosjekttidslinje" -Url "$($Uri.LocalPath)/SitePages/Prosjekttidslinje.aspx"
}
if ($PreviousVersion -lt "1.5.0") {
Write-Host "[INFO] Applying PnP template [1.5.0] to [$Url]"
Apply-PnPProvisioningTemplate "$BasePath\1.5.0.pnp" -ErrorAction Stop
Write-Host "[SUCCESS] Successfully applied PnP template [1.5.0] to [$Url]" -ForegroundColor Green
}
if ($PreviousVersion -lt "1.5.5") {
Write-Host "[INFO] In version v1.5.5 we added Project timeline configuration and reworked the TimelineContent list. Merging data now as part of the upgrade"

Expand Down Expand Up @@ -34,10 +39,5 @@ if ($null -ne $LastInstall) {
Invoke-PnPQuery
}
}
if ($PreviousVersion -lt "1.5.0") {
Write-Host "[INFO] Applying PnP template [1.5.0] to [$Url]"
Apply-PnPProvisioningTemplate "$BasePath\1.5.0.pnp" -ErrorAction Stop
Write-Host "[SUCCESS] Successfully applied PnP template [1.5.0] to [$Url]" -ForegroundColor Green
}

}
92 changes: 78 additions & 14 deletions Install/Scripts/UpgradeAllSitesToLatest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,117 @@ function EnsureProjectTimelinePage($Url) {
Write-Host "`t`tCannot connect to site. Do you have access?" -ForegroundColor Red
}
else {
$existingNode = $existingNodes | Where-Object { $_.Title -eq "Prosjekttidslinje" } -ErrorAction SilentlyContinue
$existingNode = $existingNodes | Where-Object { $_.Title -eq "Prosjekttidslinje" -or $_.Title -eq "Programtidslinje" } -ErrorAction SilentlyContinue
if ($null -eq $existingNode) {
Write-Host "`t`tAdding project timeline page"
Write-Host "`t`tAdding project timeline to site"
Write-Host "`t`t`tAdding project timeline page"
$page = Add-PnPClientSidePage -Name "Prosjekttidslinje.aspx" -PromoteAs None -LayoutType SingleWebPartAppPage -CommentsEnabled:$false -Publish
Write-Host "`t`tAdding project timeline app"
Write-Host "`t`t`tAdding project timeline app"
$webpart = Add-PnPClientSideWebPart -Page "Prosjekttidslinje" -Component "Prosjekttidslinje" -WebPartProperties '{"listName":"Tidslinjeinnhold","showFilterButton":true,"showTimeline":true,"showInfoMessage":true,"showCmdTimelineList":true,"showTimelineList":true,"title":"Prosjekttidslinje"}'
$page = Set-PnPClientSidePage -Identity "Prosjekttidslinje" -LayoutType SingleWebPartAppPage -HeaderType None -Publish
Write-Host "`t`tAdding project timeline navigation item"
Write-Host "`t`t`tAdding project timeline navigation item"
$node = Add-PnPNavigationNode -Location QuickLaunch -Title "Prosjekttidslinje" -Url "SitePages/Prosjekttidslinje.aspx"
}
else {
Write-Host "`t`tThe project already has the project timeline page. " -ForegroundColor Yellow
Write-Host "`t`tThe site already has the project timeline page" -ForegroundColor Green
}

}
}

function EnsureResourceLoadIsSiteColumn($Url) {
Connect-PnPOnline -Url $Url -UseWebLogin

$ResourceAllocation = Get-PnPList -Identity "Ressursallokering" -ErrorAction SilentlyContinue
if ($null -ne $ResourceAllocation) {
$ResourceLoadSiteColumn = Get-PnPField -Identity "GtResourceLoad"
$ResourceLoadListColumn = Get-PnPField -Identity "GtResourceLoad" -List $ResourceAllocation
if ($null -ne $ResourceLoadSiteColumn) {
Write-Host "`t`tReplacing GtResourceLoad field"
$PreviousValues = Get-PnPListItem -List $ResourceAllocation -Fields "ID", "GtResourceLoad" | ForEach-Object {
@{Id = $_.Id; GtResourceLoad = $_.FieldValues["GtResourceLoad"] }
}

if ($PreviousValues.length -gt 0) {
Write-Host "`t`t`t" (ConvertTo-Json $PreviousValues -Compress)
}

$ResourceAllocationContentType = Get-PnPContentType -Identity "Ressursallokering" -List "Ressursallokering" -ErrorAction SilentlyContinue
if ($null -ne $ResourceAllocationContentType) {
Write-Host "`t`t`tRemoving old field"
$RemovedColumn = Remove-PnPField -Identity $ResourceLoadListColumn -List $ResourceAllocation -Force


Write-Host "`t`t`tAdding the site field"
$FieldLink = New-Object Microsoft.SharePoint.Client.FieldLinkCreationInformation
$FieldLink.Field = $ResourceLoadSiteColumn
$Output = $ResourceAllocationContentType.FieldLinks.Add($FieldLink)
$ResourceAllocationContentType.Update($false)
$ResourceAllocationContentType.Context.ExecuteQuery()

Write-Host "`t`t`tAdding the site field to default view"
$DefaultView = Get-PnPView -List $ResourceAllocation -Identity "Alle elementer" -ErrorAction SilentlyContinue
if ($null -ne $DefaultView) {
$DefaultView.ViewFields.Add("GtResourceLoad")
$DefaultView.Update()
$DefaultView.Context.ExecuteQuery()
}


if ($PreviousValues.length -gt 0) {
Write-Host "`t`t`tRestoring previous values"
$PreviousValues | ForEach-Object {
$ResourceLoad = $_.GtResourceLoad

if ($ResourceLoad -gt 2 ) {
# Assuming that noone had more than 200% previously
$ResourceLoad = ($ResourceLoad / 100) # Convert to percentage if it wasn't previously
}
$NewValue = Set-PnPListItem -List $ResourceAllocation -Identity $_.Id -Values @{"GtResourceLoad" = $ResourceLoad } -SystemUpdate
}
}

Write-Host "`t`t`tField swap completed" -ForegroundColor Green
}
}
else {
Write-Host "`t`tThe site already has the correct GtResourceLoad field" -ForegroundColor Green
}
}
}

function UpgradeSite($Url) {
EnsureProjectTimelinePage -Url $Url
EnsureResourceLoadIsSiteColumn -Url $Url
}

Write-Host "This script will update all existing sites in a Prosjektportalen installation. This requires you to have the SharePoint admin role"

Set-PnPTraceLog -Off
Start-Transcript -Path "$PSScriptRoot\UpgradeSites_Log-$((Get-Date).ToString('yyyy-MM-dd-HH-mm')).txt"

[System.Uri]$Uri = $PortfolioUrl
$AdminSiteUrl = (@($Uri.Scheme, "://", $Uri.Authority) -join "").Replace(".sharepoint.com", "-admin.sharepoint.com")

Connect-PnPOnline -Url $AdminSiteUrl -UseWebLogin

$PPHubSite = Get-PnPHubSite -Identity $PortfolioUrl

$ProjectsInHub = Get-PP365HubSiteChild -Identity $PPHubSite
Connect-PnPOnline -Url $AdminSiteUrl -UseWebLogin -WarningAction Ignore

# Get current logged in user
$ctx = Get-PnPContext
$ctx.Load($ctx.Web.CurrentUser)
$ctx.ExecuteQuery()
$UserName = $ctx.Web.CurrentUser.LoginName

$PPHubSite = Get-PnPHubSite -Identity $PortfolioUrl
$ProjectsInHub = Get-PP365HubSiteChild -Identity $PPHubSite

Write-Host "The following sites were found to be part of the Project Portal hub:"
$ProjectsInHub | ForEach-Object { Write-Host "`t$_" }

Write-Host "We can grant $UserName admin access to existing projects. This will ensure that all project will be upgraded. If you select no, the script will only upgrade the sites you are already an owner of."
do {
$YesOrNo = Read-Host "Do you want to grant $UserName access to all sites in the hub (listed above)? (y/n)"
}
while ("y","n" -notcontains $YesOrNo)
while ("y", "n" -notcontains $YesOrNo)

if ($YesOrNo -eq "y") {
$ProjectsInHub | ForEach-Object {
Expand All @@ -79,7 +144,7 @@ Write-Host "We can remove $UserName's admin access from existing projects."
do {
$YesOrNo = Read-Host "Do you want to remove $UserName's admin access from all sites in the hub? (y/n)"
}
while ("y","n" -notcontains $YesOrNo)
while ("y", "n" -notcontains $YesOrNo)

if ($YesOrNo -eq "y") {
$ProjectsInHub | ForEach-Object {
Expand All @@ -90,5 +155,4 @@ if ($YesOrNo -eq "y") {
}




Stop-Transcript
12 changes: 4 additions & 8 deletions Templates/JsonTemplates/_JsonTemplateProgram.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@
],
"SiteFields": [
"<Field ID=\"{8499bd48-4c5d-43ae-8e27-7968d49ca14f}\" Name=\"GtRiskFactor\" DisplayName=\"{{SiteFields_GtRiskFactor_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactor\"><Formula>=GtRiskProbability*GtRiskConsequence</Formula><FieldRefs><FieldRef Name=\"GtRiskProbability\" ID=\"{0e1b295d-2bfb-4ef6-ae92-e72068e56111}\" /><FieldRef Name=\"GtRiskConsequence\" ID=\"{554d32a0-0148-4b3c-bfc4-f101232ee501}\" /></FieldRefs></Field>",
"<Field ID=\"{62f0454d-1150-4d55-86ef-075f786d6e5c}\" Name=\"GtRiskFactorPostAction\" DisplayName=\"{{SiteFields_GtRiskFactorPostAction_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactorPostAction\"><Formula>=GtRiskProbabilityPostAction*GtRiskConsequencePostAction</Formula><FieldRefs><FieldRef Name=\"GtRiskProbabilityPostAction\" ID=\"{f81ebcb7-8791-44b0-9919-08ed5524b11d}\" /><FieldRef Name=\"GtRiskConsequencePostAction\" ID=\"{00f17233-d4c0-49d0-aebd-5004552abb17}\" /></FieldRefs></Field>"
"<Field ID=\"{62f0454d-1150-4d55-86ef-075f786d6e5c}\" Name=\"GtRiskFactorPostAction\" DisplayName=\"{{SiteFields_GtRiskFactorPostAction_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactorPostAction\"><Formula>=GtRiskProbabilityPostAction*GtRiskConsequencePostAction</Formula><FieldRefs><FieldRef Name=\"GtRiskProbabilityPostAction\" ID=\"{f81ebcb7-8791-44b0-9919-08ed5524b11d}\" /><FieldRef Name=\"GtRiskConsequencePostAction\" ID=\"{00f17233-d4c0-49d0-aebd-5004552abb17}\" /></FieldRefs></Field>",
"<Field ID=\"{88d9b92c-efed-45d0-a586-86d9196b77d0}\" Type=\"User\" Name=\"GtResourceUser\" StaticName=\"GtResourceUser\" DisplayName=\"Navn\" Description=\"Oppgi navnet på personen som allokeres/tildeles arbeid i prosjektet\" />",
"<Field ID=\"{08ac9d56-f8eb-4a2c-868f-d39fc012fcd6}\" Type=\"Number\" Name=\"GtResourceLoad\" StaticName=\"GtResourceLoad\" DisplayName=\"Belastning\" Description=\"Hva er ressursens forventede arbeidsbelastning, oppgis i tall som indikerer prosent\" Percentage=\"TRUE\" />",
"<Field ID=\"{2ae541a5-5ecc-481d-afb6-c03a6f1e71b4}\" Type=\"User\" Name=\"GtActionResponsible\" StaticName=\"GtActionResponsible\" DisplayName=\"Tiltaksansvarlig\" Description=\"Hvem er ansvarlig for å følge opp usikkerheten?\" />"
],
"Navigation": {
"QuickLaunch": [{
Expand Down Expand Up @@ -1048,9 +1051,6 @@
"AdditionalSettings": {
"EnableVersioning": true
},
"Fields": [
"<Field ID=\"{2ae541a5-5ecc-481d-afb6-c03a6f1e71b4}\" Type=\"User\" Name=\"GtActionResponsible\" StaticName=\"GtActionResponsible\" DisplayName=\"Tiltaksansvarlig\" Description=\"Hvem er ansvarlig for å følge opp usikkerheten?\" />"
],
"Views": [{
"Title": "{{View_AllItems_DisplayName}}",
"ViewFields": [
Expand Down Expand Up @@ -1442,10 +1442,6 @@
"ContentTypeBindings": [{
"ContentTypeID": "0x010004EAFF7AFCC94C2680042E6881264120"
}],
"Fields": [
"<Field ID=\"{88d9b92c-efed-45d0-a586-86d9196b77d0}\" Type=\"User\" Name=\"GtResourceUser\" StaticName=\"GtResourceUser\" DisplayName=\"Navn\" Description=\"Oppgi navnet på personen som allokeres/tildeles arbeid i prosjektet\" />",
"<Field ID=\"{08ac9d56-f8eb-4a2c-868f-d39fc012fcd6}\" Type=\"Number\" Name=\"GtResourceLoad\" StaticName=\"GtResourceLoad\" DisplayName=\"Belastning\" Description=\"Hva er ressursens forventede arbeidsbelastning, oppgis i tall som indikerer prosent\" />"
],
"Views": [{
"Title": "{{View_AllItems_DisplayName}}",
"ViewFields": [
Expand Down
12 changes: 4 additions & 8 deletions Templates/JsonTemplates/_JsonTemplateProject.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@
],
"SiteFields": [
"<Field ID=\"{8499bd48-4c5d-43ae-8e27-7968d49ca14f}\" Name=\"GtRiskFactor\" DisplayName=\"{{SiteFields_GtRiskFactor_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactor\"><Formula>=GtRiskProbability*GtRiskConsequence</Formula><FieldRefs><FieldRef Name=\"GtRiskProbability\" ID=\"{0e1b295d-2bfb-4ef6-ae92-e72068e56111}\" /><FieldRef Name=\"GtRiskConsequence\" ID=\"{554d32a0-0148-4b3c-bfc4-f101232ee501}\" /></FieldRefs></Field>",
"<Field ID=\"{62f0454d-1150-4d55-86ef-075f786d6e5c}\" Name=\"GtRiskFactorPostAction\" DisplayName=\"{{SiteFields_GtRiskFactorPostAction_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactorPostAction\"><Formula>=GtRiskProbabilityPostAction*GtRiskConsequencePostAction</Formula><FieldRefs><FieldRef Name=\"GtRiskProbabilityPostAction\" ID=\"{f81ebcb7-8791-44b0-9919-08ed5524b11d}\" /><FieldRef Name=\"GtRiskConsequencePostAction\" ID=\"{00f17233-d4c0-49d0-aebd-5004552abb17}\" /></FieldRefs></Field>"
"<Field ID=\"{62f0454d-1150-4d55-86ef-075f786d6e5c}\" Name=\"GtRiskFactorPostAction\" DisplayName=\"{{SiteFields_GtRiskFactorPostAction_DisplayName}}\" Type=\"Calculated\" Group=\"Kolonner for Prosjektportalen (Prosjekt)\" Description=\"\" ResultType=\"Number\" StaticName=\"GtRiskFactorPostAction\"><Formula>=GtRiskProbabilityPostAction*GtRiskConsequencePostAction</Formula><FieldRefs><FieldRef Name=\"GtRiskProbabilityPostAction\" ID=\"{f81ebcb7-8791-44b0-9919-08ed5524b11d}\" /><FieldRef Name=\"GtRiskConsequencePostAction\" ID=\"{00f17233-d4c0-49d0-aebd-5004552abb17}\" /></FieldRefs></Field>",
"<Field ID=\"{88d9b92c-efed-45d0-a586-86d9196b77d0}\" Type=\"User\" Name=\"GtResourceUser\" StaticName=\"GtResourceUser\" DisplayName=\"Navn\" Description=\"Oppgi navnet på personen som allokeres/tildeles arbeid i prosjektet\" />",
"<Field ID=\"{08ac9d56-f8eb-4a2c-868f-d39fc012fcd6}\" Type=\"Number\" Name=\"GtResourceLoad\" StaticName=\"GtResourceLoad\" DisplayName=\"Belastning\" Description=\"Hva er ressursens forventede arbeidsbelastning, oppgis i tall som indikerer prosent\" Percentage=\"TRUE\" />",
"<Field ID=\"{2ae541a5-5ecc-481d-afb6-c03a6f1e71b4}\" Type=\"User\" Name=\"GtActionResponsible\" StaticName=\"GtActionResponsible\" DisplayName=\"Tiltaksansvarlig\" Description=\"Hvem er ansvarlig for å følge opp usikkerheten?\" />"
],
"Navigation": {
"QuickLaunch": [{
Expand Down Expand Up @@ -852,9 +855,6 @@
"AdditionalSettings": {
"EnableVersioning": true
},
"Fields": [
"<Field ID=\"{2ae541a5-5ecc-481d-afb6-c03a6f1e71b4}\" Type=\"User\" Name=\"GtActionResponsible\" StaticName=\"GtActionResponsible\" DisplayName=\"Tiltaksansvarlig\" Description=\"Hvem er ansvarlig for å følge opp usikkerheten?\" />"
],
"Views": [{
"Title": "{{View_AllItems_DisplayName}}",
"ViewFields": [
Expand Down Expand Up @@ -1246,10 +1246,6 @@
"ContentTypeBindings": [{
"ContentTypeID": "0x010004EAFF7AFCC94C2680042E6881264120"
}],
"Fields": [
"<Field ID=\"{88d9b92c-efed-45d0-a586-86d9196b77d0}\" Type=\"User\" Name=\"GtResourceUser\" StaticName=\"GtResourceUser\" DisplayName=\"Navn\" Description=\"Oppgi navnet på personen som allokeres/tildeles arbeid i prosjektet\" />",
"<Field ID=\"{08ac9d56-f8eb-4a2c-868f-d39fc012fcd6}\" Type=\"Number\" Name=\"GtResourceLoad\" StaticName=\"GtResourceLoad\" DisplayName=\"Belastning\" Description=\"Hva er ressursens forventede arbeidsbelastning, oppgis i tall som indikerer prosent\" />"
],
"Views": [{
"Title": "{{View_AllItems_DisplayName}}",
"ViewFields": [
Expand Down