USP_DATAFORMTEMPLATE_EDIT_MKTMARKETINGPLANTEMPLATE_2

The save procedure used by the edit dataform template "Marketing Plan Template Edit Form 2".

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(50) IN Name
@SITEID uniqueidentifier IN Site
@ISDEFAULT bit IN Use this template as the default for new marketing plans
@ITEMLIST xml IN Items

Definition

Copy


CREATE procedure dbo.[USP_DATAFORMTEMPLATE_EDIT_MKTMARKETINGPLANTEMPLATE_2]
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier,
  @NAME nvarchar(50),
  @SITEID uniqueidentifier,
  @ISDEFAULT bit,
  @ITEMLIST xml
)
as
  set nocount on;

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

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

  begin try
    -- get the current default template for this site

    if @ISDEFAULT <> 0
      begin
        declare @DEFAULTID uniqueidentifier;
        select top 1 @DEFAULTID = ID from dbo.[MKTMARKETINGPLANTEMPLATE] where ([SITEID] = @SITEID or (@SITEID is null and [SITEID] is null)) and [ISDEFAULT] <> 0;

        if not @DEFAULTID is null
          if @DEFAULTID <> @ID
            update dbo.[MKTMARKETINGPLANTEMPLATE] set [ISDEFAULT] = 0, [CHANGEDBYID] = @CHANGEAGENTID where [ID] = @DEFAULTID;
      end;

    update dbo.[MKTMARKETINGPLANTEMPLATE] set
      NAME = @NAME,
      SITEID = @SITEID,
      ISDEFAULT = @ISDEFAULT,
      CHANGEDBYID = @CHANGEAGENTID,
      DATECHANGED = @CURRENTDATE
    where ID = @ID;

    if @ITEMLIST is not null
      exec dbo.[USP_MKTMARKETINGPLANTEMPLATE_GETITEMLIST_UPDATEFROMXML] @id, @ITEMLIST, @CHANGEAGENTID, @CURRENTDATE;
  end try

  begin catch
    exec dbo.[USP_RAISE_ERROR];
    return 1;
  end catch

  return 0;