USP_DATAFORMTEMPLATE_EDIT_GIVINGLEVELPROGRAM_2

The save procedure used by the edit dataform template "Giving Level Program 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.
@NAME nvarchar(100) IN Program name
@DESCRIPTION nvarchar(255) IN Description
@SMARTFIELDID uniqueidentifier IN Smart field
@GIVINGLEVELPROGRAMLEVELS xml IN Levels
@SITES xml IN Site
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_GIVINGLEVELPROGRAM_2
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier = null,
  @NAME nvarchar(100),
  @DESCRIPTION nvarchar(255),
  @SMARTFIELDID uniqueidentifier,
  @GIVINGLEVELPROGRAMLEVELS xml,
  @SITES xml,
  @CURRENTAPPUSERID uniqueidentifier = null
)
as
  set nocount on;

  if @SITES is null
  begin 
    if dbo.UFN_SITEREQUIREDFORUSER(@CURRENTAPPUSERID) = 1 
    begin
      raiserror('BBERR_GIVINGLEVELPROGRAMSITE_SITEREQUIRED',13,1);
      return 1;
    end
  end

  if @GIVINGLEVELPROGRAMLEVELS is null
  begin
       raiserror('BBERR_GIVINGLEVEL_LEVELREQUIRED',13,1);
      return 1;
  end


  if @ID is null
    set @ID = newid();

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

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

  begin try
    update
      dbo.[GIVINGLEVELPROGRAM]
    set
      [NAME] = @NAME,
      [DESCRIPTION] = @DESCRIPTION,
      [SMARTFIELDID] = @SMARTFIELDID,
      [CHANGEDBYID] = @CHANGEAGENTID,
      [DATECHANGED] = @CURRENTDATE
    where
      [ID] = @ID;

    exec dbo.USP_GIVINGLEVELPROGRAM_GETLEVELS_UPDATEFROMXML @ID, @GIVINGLEVELPROGRAMLEVELS, @CHANGEAGENTID;

    exec dbo.USP_GIVINGLEVELPROGRAMSITE_GETSITES_UPDATEFROMXML @ID, @SITES, @CHANGEAGENTID;
  end try
  begin catch
    exec dbo.USP_RAISE_ERROR;
    return 1;
  end catch

  return 0;