USP_DATAFORMTEMPLATE_EDIT_GROUPMEMBERREMOVE
The save procedure used by the edit dataform template "Remove Group Member Edit Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | The input ID parameter indicating the ID of the record being edited. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
@MAINTAINHISTORY | bit | IN | Maintain member history with group |
@DATETO | date | IN | The constituent was a member through |
@COMMENTS | nvarchar(300) | IN | Comments |
@CLEARRECOGNITIONDEFAULTS | bit | IN | Stop member from receiving recognition |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_GROUPMEMBERREMOVE
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier,
@MAINTAINHISTORY bit,
@DATETO date,
@COMMENTS nvarchar(300),
@CLEARRECOGNITIONDEFAULTS bit
)
as begin
declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()
if @DATETO is null
set @DATETO = @CURRENTDATE;
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
-- Clear any recognition defaults b/w the household and member
declare @GROUPID uniqueidentifier, @MEMBERID uniqueidentifier
select
@GROUPID = GROUPID,
@MEMBERID = MEMBERID
from dbo.GROUPMEMBER where ID = @ID
begin try
declare @contextCache varbinary(128);
--cache current context information
set @contextCache = CONTEXT_INFO();
--set CONTEXT_INFO to @CHANGEAGENTID
set CONTEXT_INFO @CHANGEAGENTID;
if @CLEARRECOGNITIONDEFAULTS = 1
delete from dbo.REVENUERECOGNITIONDEFAULT
where
(SOURCECONSTITUENTID = @GROUPID and
RECIPIENTCONSTITUENTID = @MEMBERID)
or
(SOURCECONSTITUENTID = @MEMBERID and
RECIPIENTCONSTITUENTID = @GROUPID);
if @MAINTAINHISTORY = 1
begin
--If the primary member is removed from the group, then they should no longer be the primary member
update dbo.GROUPMEMBER
set ISPRIMARY = 0
where ID = @ID;
if @DATETO > @CURRENTDATE
begin
raiserror ('ERR_DATETO_CANNOT_BE_IN_FUTURE',13,1);
return 1;
end
update dbo.GROUPMEMBERDATERANGE
set DATETO = @DATETO,
COMMENTS = @COMMENTS,
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where GROUPMEMBERID = @ID
and ID = (select top 1 ID
from dbo.GROUPMEMBERDATERANGE
where GROUPMEMBERID = @ID
and DATETO is null);
exec dbo.USP_GROUPMEMBERROLE_UPDATEDATES @ID, @CHANGEAGENTID;
end
else
begin
delete from dbo.GROUPMEMBER where ID = @ID;
end
-- If the group member is set as a contact for correspondence, raise an error
if exists (
select
MAILPREFERENCEGROUPCONTACT.ID
from
MAILPREFERENCEGROUPCONTACT
left outer join
dbo.MAILPREFERENCE on MAILPREFERENCE.ID = MAILPREFERENCEGROUPCONTACT.MAILPREFERENCEID
where
MAILPREFERENCE.CONSTITUENTID = @GROUPID
and
MAILPREFERENCEGROUPCONTACT.CONSTITUENTID = @MEMBERID
) begin
raiserror('ERR_MAILPREFERENCEGROUPCONTACT_CONTACTISMEMBER',13,1);
return 1;
end
--reset CONTEXT_INFO to previous value
if not @contextCache is null
set CONTEXT_INFO @contextCache;
end try
begin catch
exec dbo.USP_RAISE_ERROR
return 1
end catch
return 0;
end