microsoft / coe-starter-kit

Other
739 stars 216 forks source link

[ALM Accelerator - BUG]: ISSUE with SharePoint environment variables in configure deployment settings #3089

Closed raphaelcharreyron-bib closed 1 year ago

raphaelcharreyron-bib commented 2 years ago

Describe the issue

There's an issue when we have 3 SharePoint sites (1 per environment). When we change environment and we save the data, all is OK but when we reload the screen and change from the first environment selected, data are not displayed even if data are in Dataverse. This is because the SharePoint list is not refreshed each time we change the environment. I've fixed the issue on my side with an unmanaged layer... Also I've added a Sort(..., 'Step Number') for the environments drop down to be sorted in a logical order.

Expected Behavior

When we switch from one environment to another, display the values saved in Dataverse in table User Settings.

What component are you experiencing the issue with?

ALM Accelerator Canvas App

What solution version are you using?

1.0.20220517.1

Steps To Reproduce

1- Open screen "Configure Deployment Settings" 2- Set values for SharePoint Variables (Site and lists) for the first environment selected by default 3- Select another environment in the dropdown 4- Set values for SharePoint Variables (Site and lists) 5- Click "Save and Close" 6- Re-open the window "Configure Deployment Settings" 7- Select the second environment you have set the values not the default one. 8- Check that your values are not selected in SharePoint site dropdown because it has still the sites from the default environment. 9 - Check you're data are well saved in Dataverse

Anything else?

Added code in bold...

I've updated the code in DeploymentSettingsScreen.OnVisible:

ClearCollect( DeploymentEnvironments, AddColumns( Sort(DeploymentSteps,'Step Number'), "EnvironmentUrl", 'Deployment Environment'.URL, "EnvironmentId", LookUp( AllEnvironments, 'Deployment Environment'.URL in properties.linkedEnvironmentMetadata.instanceUrl ).name, "EnvironmentUniqueName", LookUp( AllEnvironments, 'Deployment Environment'.URL in properties.linkedEnvironmentMetadata.instanceUrl ).properties.linkedEnvironmentMetadata.uniqueName, //TODO: May want to make the build name a setting on the Step. For now assume a build exists with the appropriate name "BuildName", "deploy-" & Lower(Name) & "-" & SelectedSolutionToConfigure.uniquename ) );

I fixed the issue by modifying this code in "fncLoadEnvironmentDeploymentSettings"

UpdateContext( { showSolutionComponentLoader: true, DeploymentSettingsLoadingText: "LOADING DEPLOYMENT ENVIRONMENT CONFIGURATION..." } ); If( IsBlank(drpDeployEnvironments.Selected), UpdateContext({SelectedDeploymentEnvironment: First(DeploymentEnvironments)}), UpdateContext({SelectedDeploymentEnvironment: drpDeployEnvironments.Selected}) ); If(!IsBlank(SelectedDeploymentEnvironment), UpdateContext({locSolutionEnvironmentDeploySettingName: DeploymentSettingName & " - " & SelectedSolutionToConfigure.uniquename & " - " & SelectedDeploymentEnvironment.EnvironmentUrl}); UpdateContext( { locEnvironmentDeploymentSetting: LookUp( 'User Settings', Name = locSolutionEnvironmentDeploySettingName ) } ); If( IsBlank(locEnvironmentDeploymentSetting.Data), UpdateContext({EnvironmentDeploymentSettings: ParseDeploymentSettings.Run("[]")}), UpdateContext({EnvironmentDeploymentSettings: ParseDeploymentSettings.Run(locEnvironmentDeploymentSetting.Data)}); UpdateContext( { locSharepointFilter: Concat( Distinct( Filter( EnvironmentDeploymentSettings, StartsWith( Name, "environmentvariable." ) And !IsBlankOrError(Value) And !IsBlank( Find( "sharepoint", Value ) ) ), Value ), "site:" & Result, " OR " ) } ) ); Concurrent( ClearCollect( EnvironmentTeams, SearchDeploymentEnvironmentTeams.Run( Last( FirstN( Split( SelectedDeploymentEnvironment.EnvironmentUrl, "." ), 2 ) ).Result, LookUp( AllEnvironments, SelectedDeploymentEnvironment.EnvironmentUrl in properties.linkedEnvironmentMetadata.instanceUrl ).properties.linkedEnvironmentMetadata.uniqueName, { text_3: "", text_4: "" } ) ), ClearCollect( EnvironmentUsers, SearchDeploymentEnvironmentUsers.Run( Last( FirstN( Split( SelectedDeploymentEnvironment.EnvironmentUrl, "." ), 2 ) ).Result, LookUp( AllEnvironments, SelectedDeploymentEnvironment.EnvironmentUrl in properties.linkedEnvironmentMetadata.instanceUrl ).properties.linkedEnvironmentMetadata.uniqueName, { text_3: "", text_4: "" } ) ), ClearCollect( SharepointSites, SearchSharepointSites.Run( { text: "", text_1: locSharepointFilter } ).value ), ClearCollect( GroupTeams, AddColumns( Filter( EnvironmentDeploymentSettings, StartsWith( Name, "groupteam" ) ), "DisplayName", Last( FirstN( Split( Name, "." ), 3 ) ).Result, "Id", Last( FirstN( Split( Name, "." ), 2 ) ).Result, "AADGroups", TeamAADGroups, "FilterVisible", false, "FilterIcon", Icon.FilterFlat, "SelectedRoles", Data ) ) ) );

// Add an empty row & Sort SharePoint sites Collect( SharepointSites, {webUrl: ""} ); ClearCollect( SharepointSites, Sort( SharepointSites, webUrl ) ); ClearCollect( SharepointSitesSorted, // Used to update collection SolutionEnvironmentVariables SharepointSites );

Clear(GroupTeamSelectedRoles); ForAll( GroupTeams As gt, If( IsBlankOrError( LookUp( EnvironmentTeams, name = gt.Name ) ), Collect( EnvironmentTeams, { name: gt.DisplayName, teamid: gt.Id } ); ); ForAll( Split( gt.SelectedRoles, "," ), Collect( GroupTeamSelectedRoles, AddColumns( Filter( 'Security Roles', name = Result ), "GroupTeamId", gt.Id ) ) );

); //Add an empty row to EnvironmentTeams Collect( EnvironmentTeams, {name: ""} ); ClearCollect( EnvironmentTeams, Sort( EnvironmentTeams, name, Ascending ) ); //Add an empty row to EnvironmentUsers Collect( EnvironmentUsers, {internalemailaddress: ""} ); ClearCollect( EnvironmentUsers, Sort( EnvironmentUsers, internalemailaddress, Ascending ) ); Concurrent( UpdateIf( SolutionConnectionReferences, true, { CurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "connectionreference." & connectionreferencelogicalname ).Value } ), UpdateIf( SolutionEnvironmentVariables, true, { CurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "environmentvariable." & schemaname ).Value, SharepointSites:SharepointSitesSorted } ), UpdateIf( SolutionCanvasApps, true, { CurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "canvasshare.aadGroupId." & name ).Value, CurrentPermission: LookUp( EnvironmentDeploymentSettings, Name = "canvasshare.roleName." & name ).Value } ), UpdateIf( SolutionFlows, true, { CurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "owner.ownerEmail." & Substitute( name, " ", "" ) & "." & workflowid ).Value, EnvironmentUsers: EnvironmentUsers, ActivationCurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "activateflow.activateas." & Substitute( name, " ", "" ) & "." & workflowid ).Value, ActivationEnvironmentUsers: EnvironmentUsers, SharingCurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "flow.sharing." & Substitute( name, " ", "" ) & "." & workflowid ).Value, SortOrder: LookUp( EnvironmentDeploymentSettings, Name = "activateflow.order." & Substitute( name, " ", "" ) & "." & workflowid ).Value, Activate: LookUp( EnvironmentDeploymentSettings, Name = "activateflow.activate." & Substitute( name, " ", "" ) & "." & workflowid ).Value } ), UpdateIf( CustomConnectors, true, { CurrentValue: LookUp( EnvironmentDeploymentSettings, Name = "connector.teamname." & Substitute( displayname, " ", "" ) & "." & connectorid ).Value } ), ClearCollect( EnvironmentConnections, AddColumns( PowerAppsforMakers.GetConnections( { '$filter': "environment eq '" & LookUp( AllEnvironments, SelectedDeploymentEnvironment.EnvironmentUrl in properties.linkedEnvironmentMetadata.instanceUrl, name ) & "'", 'api-version': "2016-11-01", '$top': 100 } ).value, "DisplayName", properties.displayName, "ConnectionId", name, "ApiId", properties.apiId, "IconUrl", properties.iconUri, "Status", First(properties.statuses).status ) ) ); ClearCollect( lclSolutionFlowsTemp, SolutionFlows ); ForAll( lclSolutionFlowsTemp As sf, If( IsBlankOrError(sf.SortOrder), Patch( SolutionFlows, LookUp( SolutionFlows, sf.workflowid = workflowid ), { SortOrder: CountIf( SolutionFlows, !IsBlankOrError(SortOrder) ) + 1 } ) ) ); //Add any connections that the current user doesn't have permissions to access ClearCollect( locUnsharedConnections, Filter( SolutionConnectionReferences, !IsBlankOrError(CurrentValue) And !(CurrentValue in EnvironmentConnections.ConnectionId) ) ); If( CountRows(locUnsharedConnections) > 0, UpdateContext( { locConnectorSearchCriteria: Concat( Distinct( locUnsharedConnections, connectorid ), "id eq '" & Result & "' or " ) } ); UpdateContext( { locConnectorSearchCriteria: Left( locConnectorSearchCriteria, Len(locConnectorSearchCriteria) - 3 ) } ); ClearCollect( locConnectors, PowerAppsforMakers.GetConnectors({'$filter': "environment eq '" & SelectedEnvironment.name & "' and " & locConnectorSearchCriteria}).value ); ForAll( locUnsharedConnections, If( IsEmpty( Filter( EnvironmentConnections, ConnectionId = CurrentValue ) ), Collect( EnvironmentConnections, { ApiId: connectorid, ConnectionId: CurrentValue, DisplayName: "Existing Unshared Connection", Status: "Unknown", IconUrl: First( Filter( locConnectors, id = connectorid ) ).properties.iconUri } ) ) ) );

Clear(SharepointLists); ForAll( Filter( SolutionEnvironmentVariables, type = 100000004 And parameterkey = "dataset" ), If( Not IsBlank(CurrentValue) And Not IsBlank( First( Filter( SharepointSites, webUrl = CurrentValue ) ).id ), Collect( SharepointLists, AddColumns( SearchSharepointLists.Run( LookUp( SharepointSites, webUrl = CurrentValue ).id ).value, "DefinitionId", environmentvariabledefinitionid ) ) ) ); UpdateContext({resetEnvironment: false}); UpdateContext({resetEnvironment: true}); UpdateContext( { showDeploymentSettingsLoader: false, showSolutionComponentLoader: false } );

mikefactorial commented 2 years ago

@raphaelcharreyron-bib thanks for submitting this and for doing the research / supplying the code. Will look into incorporating this in a future release. I may have questions for you when we get around to incorporating / testing the updates. Thanks again for the contribution!

mikefactorial commented 2 years ago

If you want to submit a PR with the specific changes you made in the code it would help us expedite the update even if we don't end up merging the PR directly being able to see the specific changes would help. Thanks again

mikefactorial commented 1 year ago

Related to #2855

CoEStarterKitBot commented 1 year ago

@raphaelcharreyron-bib This has been fixed in the latest release. Please install the latest version of the toolkit following the instructions for installing updates. Note that if you do not remove the unmanaged layers as described there you will not receive updates from us.