USP_DATAFORMTEMPLATE_ADD_SYSTEMROLE

The save procedure used by the add dataform template "System Role Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@ROLENAME nvarchar(255) IN Name
@DESCRIPTION nvarchar(max) IN Description
@COPYFROMSYSTEMROLE bit IN Base this role on an existing role
@COPYSYSTEMROLEID uniqueidentifier IN Source role
@COPYUSERS bit IN Copy assigned users

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_SYSTEMROLE
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,    
    @ROLENAME nvarchar(255), 
    @DESCRIPTION nvarchar(max) = '',
    @COPYFROMSYSTEMROLE bit = 0,
    @COPYSYSTEMROLEID uniqueidentifier = null,
    @COPYUSERS bit = 0
)
as 

set nocount on;

BEGIN TRY

    IF @ID is null
        set @ID = NewID()

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

    if @COPYFROMSYSTEMROLE = 0
    begin
        declare @addReturn int;
        exec @addReturn = dbo.USP_SYSTEMROLE_ADD 
                            @ID=@ID,
                            @CHANGEAGENTID=@CHANGEAGENTID,
                            @ROLENAME=@ROLENAME,
                            @DESCRIPTION=@DESCRIPTION;

        return @addReturn;
    end
    else
    begin
        if @COPYSYSTEMROLEID is null
            raiserror('ERR_COPYSYSTEMROLEIDBLANK', 16, 10);

        declare @copyReturn int;
        exec @copyReturn = dbo.USP_SYSTEMROLE_COPY
                            @ID = @ID,
                            @CHANGEAGENTID = @CHANGEAGENTID,
                            @ROLENAME = @ROLENAME,
                            @DESCRIPTION = @DESCRIPTION,
                            @SYSTEMROLEID = @COPYSYSTEMROLEID,
                            @COPYUSERS = @COPYUSERS;

        return @copyReturn;
    end

    return 0;

END TRY

BEGIN CATCH
    exec dbo.USP_RAISE_ERROR
    return 1
END CATCH