USP_RECORDOPERATION_GROUPMEMBERDELETE

Executes the "Group Member Date Range Delete Record Operation" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


                    CREATE procedure dbo.USP_RECORDOPERATION_GROUPMEMBERDELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null
                    )
                    as
                        set nocount on

                        if @CHANGEAGENTID is null
                            exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

                        begin try
                            declare @contextCache varbinary(128);

                            --cache current context information

                            set @contextCache = CONTEXT_INFO();

                            --set CONTEXT_INFO to @CHANGEAGENTID

                            set CONTEXT_INFO @CHANGEAGENTID;

                            declare @GROUPID uniqueidentifier;
                            declare @CONSTITUENTID uniqueidentifier;
                            select
                                @GROUPID = [GROUPID],
                                @CONSTITUENTID = [MEMBERID]
                            from dbo.[GROUPMEMBER] where [ID] = @ID;

                            -- If the group member is set as a contact for correspondence, raise an error

                            if exists (
                                select
                                    [MAILPREFERENCEGROUPCONTACT].[ID]
                                from
                                    dbo.[MAILPREFERENCEGROUPCONTACT]
                                left outer join
                                    dbo.[MAILPREFERENCE] on [MAILPREFERENCE].[ID] = [MAILPREFERENCEGROUPCONTACT].[MAILPREFERENCEID]
                                where
                                    [MAILPREFERENCE].[CONSTITUENTID] = @GROUPID
                                and
                                    [MAILPREFERENCEGROUPCONTACT].[CONSTITUENTID] = @CONSTITUENTID
                            ) begin
                                raiserror('ERR_MAILPREFERENCEGROUPCONTACT_CONTACTISMEMBER',13,1);
                            end

                            delete from dbo.[GROUPMEMBERDATERANGE] where [GROUPMEMBERID] = @ID;
                            delete from dbo.[GROUPMEMBER] where [ID] = @ID;    

                            --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;