USP_FENXT_UNLINK

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


      CREATE procedure dbo.USP_FENXT_UNLINK
        (
        @ID uniqueidentifier,
        @CHANGEAGENTID uniqueidentifier
        )
        as
        begin
          delete from dbo.FENXTPROJECT where PDACCOUNTSYSTEMID = @ID;
          delete from dbo.FENXTACCOUNTFUNDREQUIREMENT where PDACCOUNTSYSTEMID = @ID;
          delete from dbo.FENXTACCOUNTCODE where PDACCOUNTSYSTEMID = @ID;
          delete from dbo.FENXTACCOUNT where PDACCOUNTSYSTEMID = @ID;
          delete from dbo.FENXTACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID = @ID;

          declare BPCURSOR cursor local fast_forward for
            select FENXTSYNCPROCESS.ID
            from dbo.FENXTSYNCPROCESS
            inner join dbo.FENXTINTEGRATION on FENXTSYNCPROCESS.FENXTINTEGRATIONID = FENXTINTEGRATION.ID
            where FENXTINTEGRATION.PDACCOUNTSYSTEMID = @ID;

          open BPCURSOR
            declare @BPID uniqueidentifier;

          fetch next from BPCURSOR into @BPID
          while @@FETCH_STATUS = 0
            begin
              exec dbo.USP_RECORDOPERATION_FENXTSYNCPROCESS @BPID, @CHANGEAGENTID;
              fetch next from BPCURSOR into @BPID
            end

          close BPCURSOR;
          deallocate BPCURSOR;

          delete from dbo.FENXTINTEGRATION where PDACCOUNTSYSTEMID = @ID;

          --if there are no other Financial Edge NXT integrations then clear the FENXTFISCALYEARSTAGING table

          if not exists (select (1) from dbo.FENXTINTEGRATION) 
          begin
            truncate table dbo.FENXTFISCALYEARSTAGING
            truncate table dbo.FENXTFISCALYEAR
            truncate table dbo.FENXTFISCALPERIOD
          end;

        end