USP_DATAFORMTEMPLATE_ADD_CAMPAIGNPRIORITY

The save procedure used by the add dataform template "Campaign Priority 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.
@GOAL money IN Goal
@CAMPAIGNPRIORITYTYPECODEID uniqueidentifier IN Type
@CAMPAIGNSUBPRIORITIES xml IN Subpriorities
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.

Definition

Copy


                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_CAMPAIGNPRIORITY (
                        @ID uniqueidentifier = null output,
                        @CAMPAIGNID uniqueidentifier,
                        @GOAL money = null,
                        @CAMPAIGNPRIORITYTYPECODEID uniqueidentifier = null,
                        @CAMPAIGNSUBPRIORITIES xml = null,
                        @CHANGEAGENTID uniqueidentifier = null
                    ) as begin

                        set nocount on;

                        begin try

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

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

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

                            declare @BASECURRENCYID uniqueidentifier;
                            declare @ORGANIZATIONAMOUNT decimal(20,8);
                            declare @CURRENCYEXCHANGERATEID uniqueidentifier;
                            declare @ORGANIZATIONCURRENCYID uniqueidentifier;
                            set @ORGANIZATIONCURRENCYID = dbo.UFN_CURRENCY_GETORGANIZATIONCURRENCY();

                            select
                                @BASECURRENCYID = CAMPAIGN.BASECURRENCYID
                            from
                                dbo.CAMPAIGN
                            where
                                CAMPAIGN.ID = @CAMPAIGNID;

                            if (@ORGANIZATIONCURRENCYID = @BASECURRENCYID)
                            begin
                                set @ORGANIZATIONAMOUNT = @GOAL;

                                --Bug 84308 - AdamBu - 3/5/10 - Update the org amount in the subpriorities XML.

                                set @CAMPAIGNSUBPRIORITIES=(
                                    select 
                                        BASECURRENCYID,
                                        null CURRENCYEXCHANGERATEID,
                                        GOAL,
                                        ID,
                                        CAMPAIGNSUBPRIORITYNAMECODEID,
                                        GOAL ORGANIZATIONAMOUNT
                                    from 
                                        dbo.UFN_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_FROMITEMLISTXML(@CAMPAIGNSUBPRIORITIES)
                                    for xml raw('ITEM'),type,elements,root('CAMPAIGNSUBPRIORITIES'),BINARY BASE64
                                )
                            end
                            else
                            begin
                                set @CURRENCYEXCHANGERATEID = dbo.UFN_CURRENCYEXCHANGERATE_GETLATEST(@BASECURRENCYID, @ORGANIZATIONCURRENCYID, @CURRENTDATE, 0, null);
                                set @ORGANIZATIONAMOUNT = dbo.UFN_CURRENCY_CONVERT(@GOAL, @CURRENCYEXCHANGERATEID);

                                --Bug 84308 - AdamBu - 3/5/10 - Update the org amount and exchange rate in the subpriorities XML.

                                set @CAMPAIGNSUBPRIORITIES=(
                                    select 
                                        BASECURRENCYID,
                                        @CURRENCYEXCHANGERATEID CURRENCYEXCHANGERATEID,
                                        GOAL,
                                        ID,
                                        CAMPAIGNSUBPRIORITYNAMECODEID,
                                        dbo.UFN_CURRENCY_CONVERT(GOAL, @CURRENCYEXCHANGERATEID) ORGANIZATIONAMOUNT
                                    from 
                                        dbo.UFN_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_FROMITEMLISTXML(@CAMPAIGNSUBPRIORITIES)
                                    for xml raw('ITEM'),type,elements,root('CAMPAIGNSUBPRIORITIES'),BINARY BASE64
                                )
                            end

                            insert into dbo.CAMPAIGNPRIORITY (
                                ID,
                                CAMPAIGNID,
                                GOAL,
                                CAMPAIGNPRIORITYTYPECODEID,
                                ORGANIZATIONAMOUNT,
                                CURRENCYEXCHANGERATEID,
                                ADDEDBYID,
                                CHANGEDBYID,
                                DATEADDED,
                                DATECHANGED
                            ) values (
                                @ID,
                                @CAMPAIGNID,
                                @GOAL,
                                @CAMPAIGNPRIORITYTYPECODEID,
                                @ORGANIZATIONAMOUNT,
                                @CURRENCYEXCHANGERATEID,
                                @CHANGEAGENTID,
                                @CHANGEAGENTID,
                                @CURRENTDATE,
                                @CURRENTDATE
                            )

                            exec dbo.USP_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_ADDFROMXML @ID, @CAMPAIGNSUBPRIORITIES, @CHANGEAGENTID, @CURRENTDATE;

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

                        return 0;

                    end