Announcement

As of April 17, 2018, this site is now in read-only mode. To start new Blackbaud Developer’s discussions, you will find Developer Discussions in the Blackbaud CRM Community.

To post or respond to Blackbaud Community discussions, you will have to login using a www.blackbaud.com login. Learn how to login here. If you have questions or need assistance, please email community@blackbaud.com.

1.7k questions

3.2k answers

401 users

Categories

1.7k questions

3.2k answers

401 users

I am trying to extend the Cancel Sponsorship Edit Form by adding a field for adding a sponsorship pending reason to the sponsorship opportunity.

enter image description here

But when I save the form I have this message :
"Data could not be saved. The record being updated has been changed by another user."

Do you have any idea?

Thanks

asked by ldournaux (151 points)

Can you post your code?

Can you post the entire spec?

Here is the spec :

<SPDataForm>

	<!-- define the edit load SP, which is used to load the data for the form -->
	<LoadImplementation SPName="USR_PLAN_USP_DATAFORMTEMPLATE_EDITLOAD_USR_PLAN_SPONSORSHIPCANCELEXTENSION">
		<c:CreateProcedureSQL>
			<![CDATA[

create procedure dbo.USR_PLAN_USP_DATAFORMTEMPLATE_EDITLOAD_USR_PLAN_SPONSORSHIPCANCELEXTENSION
(

@ID uniqueidentifier,
@DATALOADED bit = 0 output,
@TSLONG bigint = 0 output,
  @SPONSORSHIPREASONID uniqueidentifier = null output,
@SPONSORSHIPOPPORTUNITYID uniqueidentifier = null output

)
as

set nocount on;

-- be sure to set these, in case the select returns no rows
set @DATALOADED = 1
set @TSLONG = 0

-- populate the output parameters, which correspond to fields on the form.  Note that
-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
-- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency
-- can be considered.
select
	@DATALOADED = 1,
	@TSLONG = TSLONG,
	@SPONSORSHIPREASONID = ID
from dbo.SPONSORSHIPREASON 

where reason='Missing SCI'

select

       @DATALOADED = 1,
       @TSLONG = TSLONG,
       @SPONSORSHIPOPPORTUNITYID = SPONSORSHIPOPPORTUNITYID
    from
       dbo.SPONSORSHIP
    where
       ID = @ID
    and
       STATUSCODE = 1
    and not exists(select 'x'
                   from dbo.SPONSORSHIP PENDING
                   where PENDING.SPONSORSHIPCOMMITMENTID = SPONSORSHIP.SPONSORSHIPCOMMITMENTID
                   and PENDING.STATUSCODE = 0)
    return 0;
			]]>
		</c:CreateProcedureSQL>
	</LoadImplementation>

	<SaveImplementation SPName="USR_PLAN_USP_DATAFORMTEMPLATE_EDIT_USR_PLAN_SPONSORSHIPCANCELEXTENSION">
		<c:CreateProcedureSQL>
			<![CDATA[
create procedure dbo.USR_PLAN_USP_DATAFORMTEMPLATE_EDIT_USR_PLAN_SPONSORSHIPCANCELEXTENSION 
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @SPONSORSHIPREASONID uniqueidentifier,
  @SPONSORSHIPOPPORTUNITYID uniqueidentifier
)
as

    set nocount on;

    if @CHANGEAGENTID is null  
	    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
			
    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()
  
  BEGIN TRY
  if @SPONSORSHIPOPPORTUNITYID != null
  begin
        declare @REASONEXIST tinyint
      --Check the pending reason exist on this child
      select @REASONEXIST = count(*) from dbo.SPONSORSHIPOPPORTUNITYREASON
      where SPONSORSHIPOPPORTUNITYREASON.SPONSORSHIPREASONID = @SPONSORSHIPREASONID
      and SPONSORSHIPOPPORTUNITYREASON.SPONSORSHIPOPPORTUNITYID = @SPONSORSHIPOPPORTUNITYID
            
      if @REASONEXIST = 0
      begin                       
          insert into dbo.SPONSORSHIPOPPORTUNITYREASON 
          (ID,
           SPONSORSHIPOPPORTUNITYID,
           SPONSORSHIPREASONID,                
           ADDEDBYID, 
           CHANGEDBYID, 
           DATEADDED, 
           DATECHANGED)
         select newid(),
          @SPONSORSHIPOPPORTUNITYID,
          @SPONSORSHIPREASONID, 
          @CHANGEAGENTID, 
          @CHANGEAGENTID, 
          @CURRENTDATE, 
          @CURRENTDATE
       end       
    end
    else
    begin
        declare @INFOMSG2 nvarchar(100);
        set @INFOMSG2 = 'Error no sponsorship opportunity record found : ' + Cast(@ID as nvarchar(max));
	        raiserror(@INFOMSG2, 16, 1);
        exec dbo.USP_RAISE_ERROR;
	        return 1;
    end
    END TRY
    BEGIN CATCH
        DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;

        SELECT @ErrorMessage = 'Error adding pending reason ' + ERROR_MESSAGE(),
           @ErrorSeverity = ERROR_SEVERITY(),
           @ErrorState = ERROR_STATE();

        RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
               );
    END CATCH
return 0;
			]]>
		</c:CreateProcedureSQL>
	</SaveImplementation>

</SPDataForm>

<!-- describe fields on the form, which correspond to parameters on the SP.  Note that system paramters 
like the record ID, DATALOADED, TSLONG, and CURRENTAPPUSERID need not be listed. -->
<FormMetaData xmlns="bb_appfx_commontypes">
	<FormFields>
  <FormField FieldID="SPONSORSHIPOPPORTUNITYID" DataType="Guid" Caption="Id" Hidden="true" />
  <FormField FieldID="SPONSORSHIPREASONID" DataType="Guid" Required="true" Caption="Pending reason">
    <SimpleDataList SimpleDataListID="c8d3128e-a2eb-4413-b0b4-1585ad5bf001">
      <Params>
        <Param ID="TYPE">
          <Value>0</Value>
        </Param>
      </Params>
    </SimpleDataList>
  </FormField>			
	</FormFields>
</FormMetaData>

<c:DataFormExtension DataFormInstanceID="4289a604-c9be-4d32-ab54-bbd4d15ee7b6" RenderStyle="AfterParent" TabCaption="" />

Are you sure you are extending this form? I don't see the extension tag at the end.

Here is the last line which was skipped :

<c:DataFormExtension DataFormInstanceID="4289a604-c9be-4d32-ab54-bbd4d15ee7b6" RenderStyle="AfterParent" TabCaption="" />

2 Answers

 
Best answer

You are setting TSLONG twice in the edit load. Try removing one of those and see what happens.

answered by chriswhisenhunt (3.9k points)
selected by ldournaux

Yes, that was it. Thanks

The code to save the form is below :

create procedure dbo.USR_PLAN_USP_DATAFORMTEMPLATE_EDIT_USR_PLAN_SPONSORSHIPCANCELEXTENSION 
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @SPONSORSHIPREASONID uniqueidentifier,
  @SPONSORSHIPOPPORTUNITYID uniqueidentifier
)
as

    set nocount on;

    if @CHANGEAGENTID is null  
	    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
			
    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()
  
  BEGIN TRY
  if @SPONSORSHIPOPPORTUNITYID != null
  begin
        declare @REASONEXIST tinyint
      --Check the pending reason exist on this child
      select @REASONEXIST = count(*) from dbo.SPONSORSHIPOPPORTUNITYREASON
      where SPONSORSHIPOPPORTUNITYREASON.SPONSORSHIPREASONID = @SPONSORSHIPREASONID
      and SPONSORSHIPOPPORTUNITYREASON.SPONSORSHIPOPPORTUNITYID = @SPONSORSHIPOPPORTUNITYID
            
      if @REASONEXIST = 0
      begin                       
          insert into dbo.SPONSORSHIPOPPORTUNITYREASON 
          (ID,
           SPONSORSHIPOPPORTUNITYID,
           SPONSORSHIPREASONID,                
           ADDEDBYID, 
           CHANGEDBYID, 
           DATEADDED, 
           DATECHANGED)
         select newid(),
          @SPONSORSHIPOPPORTUNITYID,
          @SPONSORSHIPREASONID, 
          @CHANGEAGENTID, 
          @CHANGEAGENTID, 
          @CURRENTDATE, 
          @CURRENTDATE
       end       
    end
    else
    begin
        declare @INFOMSG2 nvarchar(100);
        set @INFOMSG2 = 'Error no sponsorship opportunity record found : ' + Cast(@ID as nvarchar(max));
	        raiserror(@INFOMSG2, 16, 1);
        exec dbo.USP_RAISE_ERROR;
	        return 1;
    end
    END TRY
    BEGIN CATCH
        DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;

        SELECT @ErrorMessage = 'Error adding pending reason ' + ERROR_MESSAGE(),
           @ErrorSeverity = ERROR_SEVERITY(),
           @ErrorState = ERROR_STATE();

        RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
               );
    END CATCH
return 0;
answered by ldournaux (151 points)
...