USP_DATAFORMTEMPLATE_EDIT_BUSINESSPROCESSINSTANCEWITHSITE_PERMISSIONS

The save procedure used by the edit dataform template "Edit Business Process Instance Permissions With Site".

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.
@SECURITYLEVEL tinyint IN This feature is available for
@SYSTEMROLELIST xml IN System roles
@SITEID uniqueidentifier IN Site

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_BUSINESSPROCESSINSTANCEWITHSITE_PERMISSIONS(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,    
    @SECURITYLEVEL tinyint,
    @SYSTEMROLELIST xml,
    @SITEID uniqueidentifier    
) AS

set nocount on;

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

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

BEGIN TRY
    declare @contextCache varbinary(128);

    --cache current context information

    set @contextCache = CONTEXT_INFO();

    --set CONTEXT_INFO to @CHANGEAGENTID

    set CONTEXT_INFO @CHANGEAGENTID;

    declare @BPID uniqueidentifier;
    select @BPID = ID from dbo.BUSINESSPROCESSINSTANCE where BUSINESSPROCESSPARAMETERSETID = @ID;

    if @SECURITYLEVEL = 1
        begin                
            -- rebuild the system role list

            set @SYSTEMROLELIST = 
                (select ID, SYSTEMROLEID, GRANTORDENY
                 from dbo.UFN_BUSINESSPROCESSINSTANCE_SYSTEMROLEPERMISSIONSLIST_FROMITEMLISTXML(@SYSTEMROLELIST)
                 where (GRANTORDENY = 0) or (GRANTORDENY = 1)
                 for xml raw('ITEM'), type, elements, root('SYSTEMROLELIST'), BINARY BASE64);

            if @SYSTEMROLELIST is null
                delete from dbo.SYSTEMROLEPERM_BUSINESSPROCESSINSTANCE where BUSINESSPROCESSINSTANCEID = @BPID;
            else
                exec dbo.USP_BUSINESSPROCESSINSTANCE_SYSTEMROLEPERMISSIONSLIST_UPDATEFROMXML @BPID, @SYSTEMROLELIST, @CHANGEAGENTID;
        end
    else
        -- remove rows from dbo.SYSTEMROLEPERM_BUSINESSPROCESSINSTANCE

        delete from dbo.SYSTEMROLEPERM_BUSINESSPROCESSINSTANCE where BUSINESSPROCESSINSTANCEID = @BPID;

    -- now update the flag on the ad-hoc query table

    update dbo.BUSINESSPROCESSINSTANCE set SECURITYLEVEL = @SECURITYLEVEL, CHANGEDBYID = @CHANGEAGENTID, DATECHANGED = @CURRENTDATE, SITEID = @SITEID
        where (ID = @BPID);

    --reset CONTEXT_INFO to previous value

    if not @contextCache is null
        set CONTEXT_INFO @contextCache;

    return 0;

END TRY
BEGIN CATCH
    exec dbo.USP_RAISE_ERROR;
    return 1;
END CATCH