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 built a table which is an extension of the DESIGNATIONLEVELRECIPIENT table to house some additional data about scholarships.

After building and deploying my adddata form extension spec... when I try to create a new record via the form I receive a FK violation message. I assume this is because the record has not be created yet in the primary table (DESIGNATIONLEVELRECIPIENT). How do I extend this form and make sure the base record is committed first - before populating the additional fields in my table extension?

I thought about grabbing the standard SP which creates the record in the base table and modifying it to include all of the base (standard) data fields as well as my new extended fields... is that best practice?

Thanks,
Nick

asked by nroberts (183 points)

2 Answers

 
Best answer

Figured it out... I wasn't using CONTEXTID in my insert.
Replaced ID with CONTEXTID and all is well

Thanks...

answered by nroberts (183 points)

In your table extension do you have this in the meta data?

PrimaryKeyAsForeignKeyTablename="DESIGNATIONLEVELRECIPIENT"

Then make sure that your add form has a context ID that has the record type of: DESIGNATIONLEVELRECIPIENT

The for the ID of the extension record make that the context ID.

answered by chriswhisenhunt (3.9k points)
Yep   PrimaryKeyAsForeignKeyTablename="DESIGNATIONLEVELRECIPIENT" is in the table spec.  

My procedure is as follows:

create procedure dbo.USR_USP_DATAFORMTEMPLATE_ADD_DATAFORM
      (
        @ID uniqueidentifier = null output
        , @CONTEXTID uniqueidentifier
        , @CHANGEAGENTID uniqueidentifier = null
        , @AMOUNTOFFERED money = ''
        , @AMOUNTACCEPTED money = ''
      )
      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
          -- handle inserting the data
          insert into dbo.USR_DESIGNATIONLEVELRECIPIENT_EXT
              (ID, AMOUNTACCEPTED, AMOUNTOFFERED, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
          values
              (@ID, @AMOUNTACCEPTED, @AMOUNTOFFERED, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)
   
      end try

      begin catch
          exec dbo.USP_RAISE_ERROR
          return 1
      end catch

      return 0               

I think the problem is that I am trying to create the base record in the DESIGNATIONLEVELRECIPIENT table and the fields in the table extension at the same time.
...