USP_DATAFORMTEMPLATE_EDIT_RESEARCHGROUPOWNER

The save procedure used by the edit dataform template "Research Group Permissions 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.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@OWNERID uniqueidentifier IN Owner
@OTHERSCANMODIFY bit IN Others can modify

Definition

Copy

                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_RESEARCHGROUPOWNER (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null,
                        @CURRENTAPPUSERID uniqueidentifier,
                        @OWNERID uniqueidentifier,
                        @OTHERSCANMODIFY bit
                    ) as
                        set nocount on;

                        declare @CURRENTDATE datetime;
                        set @CURRENTDATE = getdate();

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

                        declare @USERCANMODIFY bit;
                        set @USERCANMODIFY = 0;

                        select
                            @USERCANMODIFY = 1
                        from
                            dbo.RESEARCHGROUP RG
                        left join
                            dbo.APPUSER AU on AU.ID = RG.OWNERID
                        where
                            RG.ID = @ID and
                            (RG.OWNERID = @CURRENTAPPUSERID or
                             RG.OWNERID is null or
                             dbo.UFN_APPUSER_ISSYSADMIN(@CURRENTAPPUSERID) = 1);

                        begin try
                            if @USERCANMODIFY = 1 begin
                                update
                                    dbo.RESEARCHGROUP
                                set
                                    OWNERID = @OWNERID,
                                    OTHERSCANMODIFY = @OTHERSCANMODIFY,
                                    CHANGEDBYID = @CHANGEAGENTID,
                                    DATECHANGED = @CURRENTDATE
                                where
                                    ID = @ID;
                            end
                            else begin
                                raiserror ('ERR_RESEARCHGROUP_CANNOTMODIFY',13,1);
                            return 0;
                            end
                        end try
                        begin catch
                            exec dbo.USP_RAISE_ERROR;
                            return 1;
                        end catch

                        return 0;