USP_DATAFORMTEMPLATE_EDIT_PROSPECTPLANSECONDARYFUNDRAISER

The save procedure used by the edit dataform template "Prospect Plan Secondary Fundraiser 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.
@FUNDRAISERID uniqueidentifier IN Solicitor
@SOLICITORROLECODEID uniqueidentifier IN Role
@DATEFROM datetime IN Start date
@DATETO datetime IN End date

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_PROSPECTPLANSECONDARYFUNDRAISER 
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier = null,
  @FUNDRAISERID uniqueidentifier,
  @SOLICITORROLECODEID uniqueidentifier,
  @DATEFROM datetime,
  @DATETO datetime 
)
as
  set nocount on;

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

  declare @CURRENTDATE datetime = getdate();

  begin try

    update
      dbo.SECONDARYFUNDRAISER 
    set
      FUNDRAISERID = @FUNDRAISERID,
      SOLICITORROLECODEID = @SOLICITORROLECODEID,
      DATEFROM = @DATEFROM,
      DATETO = @DATETO,
      DATECHANGED = @CURRENTDATE,
      CHANGEDBYID = @CHANGEAGENTID
    where 
      ID = @ID;

    declare @PROSPECTPLANID uniqueidentifier;
    select @PROSPECTPLANID = PROSPECTPLANID from dbo.SECONDARYFUNDRAISER where ID = @ID;

    -- Assign this fundraiser to any steps tied to plan outlines that have no fundraiser assigned
    update
      dbo.INTERACTION
    set
      FUNDRAISERID = @FUNDRAISERID,
      CHANGEDBYID = @CHANGEAGENTID,
      DATECHANGED = @CURRENTDATE
    from
      dbo.PLANOUTLINESTEP
    where
      PLANOUTLINESTEP.ID = PLANOUTLINESTEPID
      and PLANOUTLINESTEP.FUNDRAISERROLECODE = 3
      and FUNDRAISERID is null
      and PROSPECTPLANID = @PROSPECTPLANID;

    -- If this is no longer a current solicitor, clean up the OPPORTUNITYSOLICITOR table
    if @DATETO < @CURRENTDATE
    begin
      declare @CONTEXTCACHE varbinary(128) = context_info();
      set context_info @CHANGEAGENTID;

      delete from
        dbo.OPPORTUNITYSOLICITOR
      where
        SECONDARYSOLICITORID = @ID;

      if not @CONTEXTCACHE is null
        set context_info @CONTEXTCACHE;
    end

  end try
  begin catch
    exec dbo.USP_RAISE_ERROR;
    return 1;
  end catch

  return 0;