USP_EMAILSCHEDULE_EMAILLIST_ADD

The save procedure used by the add dataform template "EmailSchedule_EmailList Add Data 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.
@EMAILLISTID xml IN List of EmailList Id's
@EMAILSCHEDULEID uniqueidentifier IN Email Schedule ID

Definition

Copy


CREATE procedure dbo.USP_EMAILSCHEDULE_EMAILLIST_ADD
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,
      @EMAILLISTID xml = null,
      @EMAILSCHEDULEID uniqueidentifier = null

)
as

set nocount on;

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

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

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try

  declare @ListIDs TABLE (ID int)
  declare @idoc int

  EXEC sp_xml_preparedocument @idoc OUTPUT, @EMAILLISTID
  INSERT INTO @ListIDs 
  SELECT *
  FROM OPENXML (@idoc, '/ArrayOfInt/int', 2)
  WITH ([ID] int '.')
  EXEC sp_xml_removedocument @idoc


      -- handle inserting the data

      insert into dbo.EMAILSCHEDULE_EMAILLIST
        (ID, EMAILLISTID, EMAILSCHEDULEID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)    
    (
       select newid(), ID, @EMAILSCHEDULEID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE
       from @ListIDs
    )


end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0