USP_DATAFORMTEMPLATE_EDIT_SEGMENTCOUNTENQUEUERCONFIGURATION

Parameters

Parameter Parameter Type Mode Description
@CHANGEAGENTID uniqueidentifier IN
@ISENQUEUEENABLED bit IN

Definition

Copy


                                CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_SEGMENTCOUNTENQUEUERCONFIGURATION 
                                (
                                    @CHANGEAGENTID uniqueidentifier = null,
                                    @ISENQUEUEENABLED bit 
                                )
                                as
                                set nocount on;

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

                declare @BUSINESSPROCESSID uniqueidentifier,
                        @BUSINESSPROCESSSPECXML xml,
                        @EXISTINGSETTING bit;

                declare BUSINESSPROCESSCURSOR cursor for
                select '585D30CC-C822-4441-A161-F8A2306BDA8D'    -- Marketing Effort Segment Record Count Calculation

                union all
                select '22C3D75C-A956-4BFC-A5FD-4B866BAEF509'    -- Marketing Effort Activate Process


                open BUSINESSPROCESSCURSOR;

                begin try

                  fetch next from BUSINESSPROCESSCURSOR
                  into @BUSINESSPROCESSID;

                  -- Update each spec and load it into the database

                  while @@FETCH_STATUS = 0
                  begin

                    select @BUSINESSPROCESSSPECXML = BUSINESSPROCESSSPECXML 
                    from dbo.BUSINESSPROCESSCATALOG
                    where ID = @BUSINESSPROCESSID;

                    ;WITH XMLNAMESPACES ('bb_appfx_businessprocess' as x)
                    select @EXISTINGSETTING = @BUSINESSPROCESSSPECXML.value('(/x:BusinessProcessSpec/@AllowEnqueue)[1]', 'bit');

                    if (@ISENQUEUEENABLED <> coalesce(@EXISTINGSETTING, 0))
                    begin
                      if (@EXISTINGSETTING is null)
                        set @BUSINESSPROCESSSPECXML.modify('insert attribute AllowEnqueue {"true"}into (/*)[1]');
                      else if (@ISENQUEUEENABLED = 0)
                        set @BUSINESSPROCESSSPECXML.modify(' declare default element namespace "bb_appfx_businessprocess"; replace value of (/BusinessProcessSpec/@AllowEnqueue)[1] with "false"');
                      else if (@ISENQUEUEENABLED = 1)
                        set @BUSINESSPROCESSSPECXML.modify(' declare default element namespace "bb_appfx_businessprocess"; replace value of (/BusinessProcessSpec/@AllowEnqueue)[1] with "true"');

                      exec dbo.USP_LOADSPEC @SPECXML=@BUSINESSPROCESSSPECXML,@ITEMNAME=N'',@SOURCENAME=N'',@FORCERELOAD=0,@COMPARETOEXISTINGSPECXML=0;
                    end

                    fetch next from BUSINESSPROCESSCURSOR
                    into @BUSINESSPROCESSID;
                  end

                  close BUSINESSPROCESSCURSOR;
                  deallocate BUSINESSPROCESSCURSOR;
                end try
                begin catch
                  close BUSINESSPROCESSCURSOR;
                  deallocate BUSINESSPROCESSCURSOR;

                  exec dbo.USP_RAISE_ERROR;
                  return 1;
                end catch;

                                return 0;