USP_DATAFORMTEMPLATE_ADD_DONORCHALLENGEDESIGNATIONMAPSELECTION

The save procedure used by the add dataform template "Donor Challenge Designation Map Selection 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.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@DONORCHALLENGEID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@DESIGNATIONSELECTIONID uniqueidentifier IN Designation selection
@MATCHINGDESIGNATIONID uniqueidentifier IN Default matching designation

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_DONORCHALLENGEDESIGNATIONMAPSELECTION
(
  @ID uniqueidentifier = null output,
  @CHANGEAGENTID uniqueidentifier = null,
  @CURRENTAPPUSERID uniqueidentifier,
  @DONORCHALLENGEID uniqueidentifier,
  @DESIGNATIONSELECTIONID uniqueidentifier = null,
  @MATCHINGDESIGNATIONID uniqueidentifier = null
)
as
begin
  set nocount on;

  declare @CURRENTDATE datetime = getdate();

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

  begin try
    declare @TYPECODE as tinyint;
    select @TYPECODE = TYPECODE from dbo.DONORCHALLENGE where ID = @DONORCHALLENGEID;

    insert into dbo.DONORCHALLENGEDESIGNATIONMAP
    (
      ID,
      DONORCHALLENGEID,
      DESIGNATIONID,
      MATCHINGDESIGNATIONID,
      ADDEDBYID,
      CHANGEDBYID,
      DATEADDED,
      DATECHANGED
    )
      select
      newid(),
      @DONORCHALLENGEID,
      SELECTION.ID,
      case when @TYPECODE = 1 then null else coalesce(@MATCHINGDESIGNATIONID, SELECTION.ID) end,
      @CHANGEAGENTID,
      @CHANGEAGENTID,
      @CURRENTDATE,
      @CURRENTDATE
    from
      dbo.UFN_IDSETREADER_GETRESULTS_GUID(@DESIGNATIONSELECTIONID) SELECTION

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

  return 0
end