USP_DATAFORMTEMPLATE_ADD_CAMPAIGNHIERARCHY
The save procedure used by the add dataform template "Campaign Hierarchy Add Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | INOUT | The output parameter indicating the ID of the record added. |
@CAMPAIGNID | uniqueidentifier | IN | Input parameter indicating the context ID for the record being added. |
@CAMPAIGNHIERARCHYID | uniqueidentifier | IN | Campaign hierarchy |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_CAMPAIGNHIERARCHY (
@ID uniqueidentifier = null output,
@CAMPAIGNID uniqueidentifier,
@CAMPAIGNHIERARCHYID uniqueidentifier = null,
@CHANGEAGENTID uniqueidentifier = null
) as begin
set nocount on;
-- verify that the campaign does not already belong to a hierarchy
if exists (
select
CAMPAIGN.ID
from
dbo.CAMPAIGN
where (
CAMPAIGN.ID = @CAMPAIGNID
and
CAMPAIGN.HIERARCHYPATH.GetAncestor(1) <> hierarchyid::GetRoot()
) or (
CAMPAIGN.HIERARCHYPATH.GetAncestor(1) = (select PARENT.HIERARCHYPATH from dbo.CAMPAIGN [PARENT] where PARENT.ID = @CAMPAIGNID)
)
)
raiserror ('ERR_CAMPAIGNHIERARCHY_CAMPAIGNALREADYINHIERARCHY',13,1);
if (@CAMPAIGNID = @CAMPAIGNHIERARCHYID)
raiserror ('ERR_CAMPAIGNHIERARCHY_CANTADDTOSELF',13,1);
declare @CURRENTDATE datetime;
set @CURRENTDATE = getdate();
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
begin try
update
dbo.CAMPAIGN
set
HIERARCHYPATH = dbo.UFN_CAMPAIGN_GETHIERARCHYPATHINSERTPOSITION(@CAMPAIGNHIERARCHYID),
DATECHANGED = @CURRENTDATE,
CHANGEDBYID = @CHANGEAGENTID
where
ID = @CAMPAIGNID;
set @ID = @CAMPAIGNHIERARCHYID;
end try
begin catch
exec dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;
end