Welcome to Forums Sign in | Join | Help | Forums
in Search





Make the world a better place.

API Help in .Net - Create Constituent

Last post 06-20-2008 3:15 AM by David Zeidman. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 06-18-2008 10:54 PM

    • Paul Black
    • Not Ranked
    • Posts 10
    • Organization: RMIT University
    • Products:  Blackbaud NetCommunity, The Raiser's Edge

    API Help in .Net - Create Constituent

    Hi,

    My client has purchased Raiser's Edge and requires external systems to integrate their data with RE.
    I am writing .Net code to manipulate the API to create new constituents but am running into a problem.
    I tried all the help manuals but am unsure what to do. Code is as follows:

    IBBSessionContext _context;
    private CRecord _record = new CRecord();
    .....

    _record = new CRecord();
    _record.Init(ref _context);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_CONSTITUENT_ID, id);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_CONSTITUENT_CODE, constituentCode);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_FIRST_NAME, firstName);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_MIDDLE_NAME, middleName);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_LAST_NAME, lastName);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_SOCIAL_SECURITY_NO, SSN);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_TITLE_1, title1);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_SUFFIX_1, suffix1);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_BIRTH_DATE, birthDate);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_BIRTHPLACE, birthPlace);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_ETHNICITY, ethnicity);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_MARITAL_STATUS, maritalStatus);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_GENDER, gender);

    CConstituentCode cCode = _record.ConstituentCodes.Add();
    cCode.set_Fields(ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_CODE, "Staff");
    cCode.set_Fields(ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_CONSTIT_ID, "Staff");
    if (deceasedDate.HasValue)
    {
    _record.set_Fields(ERECORDSFields.RECORDS_fld_DECEASED_DATE, deceasedDate.Value);
    _record.set_Fields(ERECORDSFields.RECORDS_fld_DECEASED, "1");
    }

    _record.Save();

    When save gets called, I get an exception with the following message:
    " System.Runtime.InteropServices.COMException (0x80040666): Required Field Missing: Constituent Code
    at BBREAPI7.CRecordClass.Save()"


    I know why it is complaining about the Constituent code as I get the same message when I try to create a new constituent from the Raiser's Edge UI. Can someone help me with adding a constituent code to the CRecord object please?

     

    Filed under: , ,
  • 06-19-2008 11:23 AM In reply to

    • David Zeidman
    • Top 25 Contributor
    • Posts 165
    • Organization: Zeidman Development
    • Products:  The Raiser's Edge

    Re: API Help in .Net - Create Constituent

     

    Earl Walk:
    CConstituentCode cCode = _record.ConstituentCodes.Add();
    cCode.set_Fields(ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_CODE, "Staff");
    cCode.set_Fields(ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_CONSTIT_ID, "Staff");

     

    Why are you assigning a value to  CONSTITUENT_CODE_fld_CONSTIT_ID? This is the parent id of the constituent code i.e. teh constituent's system id. What is probably happening is that it tries to assign "staff" to that, fails, and instead of creating an exception (which it really should) it leaves constitid blank - your missing field. Don't assign it a value as it is automatically assigned a value when you do the _record.ConstituentCodes.Add()

    David

    David Zeidman
    Zeidman Development
    http://www.zeidman.info

    Check out my RE API blog
    http://www.re-decoded.com
  • 06-19-2008 6:22 PM In reply to

    • Paul Black
    • Not Ranked
    • Posts 10
    • Organization: RMIT University
    • Products:  Blackbaud NetCommunity, The Raiser's Edge

    Re: API Help in .Net - Create Constituent

    I tried removing the CONSTITUENT_CODE_fld_CONSTIT_ID assignment but I get this error:

    System.Runtime.InteropServices.COMException (0x80040666): Required Field Missing: Status
    at BBREAPI7.CRecordClass.Save()

    I did some more investigation yesterday and discovered that if I set:

    Code:
    _record.set_Fields(ERECORDSFields.RECORDS_fld_IS_CONSTITUENT, "false");

    it works, and a record gets created in the Records table but if that variable is set to true, it throws up an error. I then tried a SQL update statement on the Records table to set the IS_CONSTITUENT field to true and it threw up a constraint error.

    It seems that if IS_CONSTITUENT = true, it needs a row in the Constituent table as well.

    I rechecked the API and cannot find a way to create a constituent in the constituent table. This is very frustrating!!

    If anyone has been able to create a constituent via the API, please help

    Filed under: ,
  • 06-19-2008 6:53 PM In reply to

    • David Zeidman
    • Top 25 Contributor
    • Posts 165
    • Organization: Zeidman Development
    • Products:  The Raiser's Edge

    Re: API Help in .Net - Create Constituent

     

     You really should not be doing updates on the database. There is a reason that manipulating data directly in the DB invalidates your maintenance agreement. You should not need to set the is_constituent  field to false either. You want to create a constituent.

    Creating a constituent is a common task so I surprised that you are unable to get it to work. You may need to see which fields your installation of RE has made mandatory. Is there a status field that is required when you enter a constituent through the GUI? In which case you have to enter it via the API too.

     One thing that I noticed was that you set the constituent code field. This should only be done using the constituent.constituentcodes.add() method. I am not sure if that will make a difference or not.

    David

    David Zeidman
    Zeidman Development
    http://www.zeidman.info

    Check out my RE API blog
    http://www.re-decoded.com
  • 06-19-2008 7:26 PM In reply to

    • Paul Black
    • Not Ranked
    • Posts 10
    • Organization: RMIT University
    • Products:  Blackbaud NetCommunity, The Raiser's Edge