@@ -1003,6 +1003,67 @@ private void LaunchWorkflowsInBackground( List<ConnectionRequest> eligibleReques
10031003
10041004 #region Placement Group Methods
10051005
1006+ /// <summary>
1007+ /// Applies a default group member role and/or status to the Connection Request
1008+ /// when the assigned placement group's opportunity offers only a single option.
1009+ /// The Edit and Add UIs hide the role/status dropdown when there is only one
1010+ /// configured value, so the bag arrives without a selection. This fills the
1011+ /// gap so the request can still be fully placed.
1012+ /// </summary>
1013+ /// <param name="entity">The Connection Request whose role/status may need defaulting.</param>
1014+ private void ApplyDefaultGroupMemberRoleAndStatus ( ConnectionRequest entity )
1015+ {
1016+ if ( ! entity . AssignedGroupId . HasValue )
1017+ {
1018+ return ;
1019+ }
1020+
1021+ if ( entity . AssignedGroupMemberRoleId . HasValue && entity . AssignedGroupMemberStatus . HasValue )
1022+ {
1023+ return ;
1024+ }
1025+
1026+ var placementGroup = new GroupService ( RockContext ) . Get ( entity . AssignedGroupId . Value ) ;
1027+ if ( placementGroup == null )
1028+ {
1029+ return ;
1030+ }
1031+
1032+ var configs = new ConnectionOpportunityGroupConfigService ( RockContext ) . Queryable ( )
1033+ . AsNoTracking ( )
1034+ . Where ( c =>
1035+ c . ConnectionOpportunityId == entity . ConnectionOpportunityId &&
1036+ c . GroupTypeId == placementGroup . GroupTypeId )
1037+ . Select ( c => new
1038+ {
1039+ c . GroupMemberRoleId ,
1040+ c . GroupMemberStatus
1041+ } )
1042+ . ToList ( ) ;
1043+
1044+ if ( ! entity . AssignedGroupMemberRoleId . HasValue )
1045+ {
1046+ var distinctRoleIds = configs . Select ( c => c . GroupMemberRoleId ) . Distinct ( ) . ToList ( ) ;
1047+ if ( distinctRoleIds . Count == 1 )
1048+ {
1049+ entity . AssignedGroupMemberRoleId = distinctRoleIds [ 0 ] ;
1050+ }
1051+ }
1052+
1053+ if ( ! entity . AssignedGroupMemberStatus . HasValue && entity . AssignedGroupMemberRoleId . HasValue )
1054+ {
1055+ var distinctStatuses = configs
1056+ . Where ( c => c . GroupMemberRoleId == entity . AssignedGroupMemberRoleId . Value )
1057+ . Select ( c => c . GroupMemberStatus )
1058+ . Distinct ( )
1059+ . ToList ( ) ;
1060+ if ( distinctStatuses . Count == 1 )
1061+ {
1062+ entity . AssignedGroupMemberStatus = distinctStatuses [ 0 ] ;
1063+ }
1064+ }
1065+ }
1066+
10061067 /// <summary>
10071068 /// Serializes the Placement Group Member Attribute values into a JSON string and returns it
10081069 /// </summary>
@@ -1706,6 +1767,10 @@ private bool UpdateEntityFromBox( ConnectionRequest entity, ValidPropertiesBox<C
17061767 box . IfValidProperty ( nameof ( box . Bag . GroupMemberStatus ) ,
17071768 ( ) => entity . AssignedGroupMemberStatus = box . Bag . GroupMemberStatus ) ;
17081769
1770+ // If the opportunity only offers a single role or status, the UI hides the dropdown,
1771+ // so the bag arrives empty. Default it before serializing attribute values.
1772+ ApplyDefaultGroupMemberRoleAndStatus ( entity ) ;
1773+
17091774 box . IfValidProperty ( nameof ( box . Bag . PlacementGroupMemberAttributeValues ) ,
17101775 ( ) => entity . AssignedGroupMemberAttributeValues = GetGroupMemberAttributeValuesFromBag ( box . Bag . PlacementGroupMemberAttributeValues , entity . AssignedGroupId , entity . AssignedGroupMemberRoleId , entity . AssignedGroupMemberStatus ) ) ;
17111776 }
0 commit comments