Skip to content

Commit

Permalink
test: Update all user settings to English (United Kingdom)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdashworth committed Jul 18, 2022
1 parent f9d349a commit c48e95e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
36 changes: 36 additions & 0 deletions scripts/Set-AllUserLocalesToUk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Install-Module -Name Microsoft.Xrm.Tooling.CrmConnector.PowerShell -Force -Scope CurrentUser -AllowClobber

Write-Host "Updating user settings to English (United Kingdom)"

$conn = Get-CrmConnection -ConnectionString "Url=$URL; ClientId=$ClientId; ClientSecret=$ClientSecret; AuthType=ClientSecret"

$condition = [Microsoft.Xrm.Sdk.Query.ConditionExpression]::new();
$condition.AttributeName = "localeid";
$condition.Operator = ConditionOperator.NotEqual;
$condition.Values.Add(2057);

$filter = [Microsoft.Xrm.Sdk.Query.FilterExpression]::new();
$filter.Conditions.Add($condition);

$query = [Microsoft.Xrm.Sdk.Query.QueryExpression]::new("usersettings");
$query.ColumnSet.AddColumns("localeid");
$query.Criteria.AddFilter($filter);

$executeMultipleSettings = [Microsoft.Xrm.Sdk.ExecuteMultipleSettings]::new()
$executeMultipleSettings.ContinueOnError = $true
$executeMultipleSettings.ReturnResponses = $false

$executeMultipleRequests = [Microsoft.Xrm.Sdk.OrganizationRequestCollection]::new()

$usersettings = $conn.RetrieveMultiple($query).Entities
$usersettings | ForEach-Object {
$_.Attributes['localeid'] = 2057
$updateRequest = [Microsoft.Xrm.Sdk.Messages.UpdateRequest]::new()
$updateRequest.Target = $_
$executeMultipleRequests.Add($updateRequest)
}

$executeMultipleRequest = [Microsoft.Xrm.Sdk.Messages.ExecuteMultipleRequest]::new()
$executeMultipleRequest.Settings = $executeMultipleSettings
$executeMultipleRequest.Requests = $executeMultipleRequests
$conn.Execute($executeMultipleRequest)
10 changes: 9 additions & 1 deletion templates/build-and-test-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ stages:
echo "##vso[task.setvariable variable=EnvironmentUrl;isOutput=true]$env:POWERPLATFORMCREATEENVIRONMENT_BUILDTOOLS_ENVIRONMENTURL"
echo "##vso[task.setvariable variable=EnvironmentName;isOutput=true]$env:POWERPLATFORMCREATEENVIRONMENT_BUILDTOOLS_ENVIRONMENTID"
displayName: Set output variables
name: SetEnvironmentOutputVariables
name: SetEnvironmentOutputVariables
- task: PowerShell@2
displayName: Update user settings to English (United Kingdom)
inputs:
filePath: '.\scripts\Set-AllUserLocalesToUk.ps1'
env:
URL: $[ SetEnvironmentOutputVariables.EnvironmentUrl ]
ClientId: $(Application User Client ID)
ClientSecret: $(Application User Client Secret)
- stage: BuildAndTest
displayName: Build and Test
dependsOn: ProvisionEnvironment
Expand Down

0 comments on commit c48e95e

Please sign in to comment.