USP_FUNDINGREQUEST_STEPSWITHCHILDREN_UPDATEFROMXML
Updates a funding request's steps along with the step's additional fundraisers.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@FUNDINGREQUESTID | uniqueidentifier | IN | |
@STEPS | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN |
Definition
Copy
create procedure dbo.USP_FUNDINGREQUEST_STEPSWITHCHILDREN_UPDATEFROMXML
(
@FUNDINGREQUESTID uniqueidentifier,
@STEPS xml,
@CHANGEAGENTID uniqueidentifier = null
)
as
set nocount on;
declare @contextCache varbinary(128);
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
/* cache current context information */
set @contextCache = CONTEXT_INFO();
/* set CONTEXT_INFO to @CHANGEAGENTID */
if not @CHANGEAGENTID is null
set CONTEXT_INFO @CHANGEAGENTID
declare @GRANTORID uniqueidentifier;
select @GRANTORID = GRANTS.GRANTORID
from dbo.FUNDINGREQUEST
inner join dbo.GRANTS on GRANTS.ID = FUNDINGREQUEST.GRANTSID
where FUNDINGREQUEST.ID = @FUNDINGREQUESTID;
set @STEPS=(
select
@GRANTORID CONSTITUENTID,
ACTUALDATE,
EXPECTEDDATE,
FUNDRAISERID,
-- Set the ID to a value known in this SP so the additional fundraisers can be inserted/updated as well
case when ID is null then newid() else ID end ID,
OBJECTIVE,
FUNDINGREQUESTSTAGECODEID,
coalesce(STATUSCODE, 0) as STATUSCODE,
FUNDINGREQUESTOUTLINESTEPID,
INTERACTIONTYPECODEID,
-- Have to perform the query so that the xml generated by this query isn't <ADDITIONALFUNDRAISERS><ADDITIONALFUNDRAISERS><ITEM>...
-- which would then break UFN_FUNDINGREQUEST_STEPSWITHCHILDREN_FROMITEMLISTXML the next time it's called
case when ADDITIONALFUNDRAISERS is null then null else ADDITIONALFUNDRAISERS.query('(ADDITIONALFUNDRAISERS/ITEM)') end as ADDITIONALFUNDRAISERS,
case when PARTICIPANTS is null then null else PARTICIPANTS.query('(PARTICIPANTS/ITEM)') end as PARTICIPANTS,
coalesce(COMMENT, '') as COMMENT
from
dbo.UFN_FUNDINGREQUEST_STEPSWITHCHILDREN_FROMITEMLISTXML(@STEPS)
for xml raw('ITEM'), type, elements, root('STEPS'), binary base64
)
-- Clear current additional fundraisers for the steps in @STEPS. If the values weren't cleared and
-- the new owner was in the additional fundraisers table but was removed, a constraint would be violated.
delete from dbo.INTERACTIONADDITIONALFUNDRAISER where INTERACTIONID in (select ID from dbo.UFN_FUNDINGREQUEST_STEPSWITHCHILDREN_FROMITEMLISTXML(@STEPS))
exec dbo.USP_FUNDINGREQUEST_STEPS_UPDATEFROMXML @FUNDINGREQUESTID, @STEPS, @CHANGEAGENTID;
-- Take care of the additional solicitors for each step
declare @INTERACTIONID uniqueidentifier, @INTERACTIONTYPECODEID uniqueidentifier, @ADDITIONALFUNDRAISERS xml, @PARTICIPANTS xml
declare STEPCURSOR cursor local fast_forward for
select
ID,
INTERACTIONTYPECODEID,
ADDITIONALFUNDRAISERS,
PARTICIPANTS
from
dbo.UFN_FUNDINGREQUEST_STEPSWITHCHILDREN_FROMITEMLISTXML(@STEPS)
open STEPCURSOR
fetch next from STEPCURSOR into @INTERACTIONID, @INTERACTIONTYPECODEID, @ADDITIONALFUNDRAISERS, @PARTICIPANTS;
while @@FETCH_STATUS = 0
begin
exec dbo.USP_INTERACTION_ADDITIONALFUNDRAISERS_UPDATEFROMXML @INTERACTIONID, @ADDITIONALFUNDRAISERS, @CHANGEAGENTID;
-- Clear participants if the step is no longer an interaction
if @INTERACTIONTYPECODEID is null
delete from dbo.INTERACTIONPARTICIPANT where INTERACTIONID = @INTERACTIONID;
else
exec dbo.USP_INTERACTION_PARTICIPANTS_UPDATEFROMXML @INTERACTIONID, @PARTICIPANTS, @CHANGEAGENTID;
fetch next from STEPCURSOR into @INTERACTIONID, @INTERACTIONTYPECODEID, @ADDITIONALFUNDRAISERS, @PARTICIPANTS;
end
close STEPCURSOR
deallocate STEPCURSOR
/* reset CONTEXT_INFO to previous value */
if not @contextCache is null
set CONTEXT_INFO @contextCache