USP_RECORDOPERATION_GROUPMEMBERREINSTATE
Executes the "Group Member Reinstate Record Operation" record operation.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | Input parameter indicating the ID of the record being updated. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the update. |
Definition
Copy
create procedure dbo.USP_RECORDOPERATION_GROUPMEMBERREINSTATE
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null
)
as
set nocount on
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
-- If the group the member is being reinstated to is a household and the
-- constituent is already a member of a different household, raise an error
declare @ISHOUSEHOLD bit, @MEMBERID uniqueidentifier, @GROUPID uniqueidentifier, @GROUPMEMBERID uniqueidentifier
select
@ISHOUSEHOLD = case when GD.GROUPTYPECODE = 0 then 1 else 0 end,
@MEMBERID = GM.MEMBERID,
@GROUPID = GM.GROUPID,
@GROUPMEMBERID = GM.ID
from dbo.GROUPMEMBERDATERANGE GMDR
inner join dbo.GROUPMEMBER GM on GMDR.GROUPMEMBERID = GM.ID
inner join dbo.GROUPDATA GD on GM.GROUPID = GD.ID
where GMDR.ID = @ID
if @ISHOUSEHOLD = 1 and dbo.UFN_GROUPMEMBER_HOUSEHOLDCOUNT(@MEMBERID) > 0
begin
raiserror('CONSTITUENTALREADYMEMBEROFHOUSEHOLD', 13, 1)
end
begin try
update dbo.GROUPMEMBERDATERANGE
set
DATETO = null,
DATECHANGED = getdate(),
CHANGEDBYID = @CHANGEAGENTID
where ID = @ID
-- Default to primary member if no other member already is
declare @ISPRIMARY bit
if not exists(select 1 from dbo.GROUPMEMBER GM where GM.GROUPID = @GROUPID and GM.ISPRIMARY = 1 and GM.MEMBERID <> @MEMBERID)
begin
update dbo.GROUPMEMBER
set
ISPRIMARY = 1,
DATECHANGED = getdate(),
CHANGEDBYID = @CHANGEAGENTID
where
ID = @GROUPMEMBERID
end
end try
begin catch
exec dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;