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


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
    • User Since: 2002
    • Posts 326
    • Organization: Zeidman Development
    • Products:  Blackbaud Direct Marketing, Blackbaud Enterprise CRM, The Information Edge, 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
    • User Since: 2002
    • Posts 326
    • Organization: Zeidman Development
    • Products:  Blackbaud Direct Marketing, Blackbaud Enterprise CRM, The Information Edge, 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

    Re: API Help in .Net - Create Constituent

    There seems to be some confusion. I am not updating data via the database, I just tried it to see if there were any constraints.

    The key field is RECORDS_fld_IS_CONSTITUENT which, if set to true, fails but if set to false works, but only inserts a row in the records table, NOT in the Constituent table. If anyone has been able to successfully create a row in the Constituent table, please help!

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

    I have tried in vain to find a Status field both in the Records table and the ERECORDSFields enumeration.

    Here is the full text of my code:

    _record = new CRecord();

    _context = _api.SessionContext;

    _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_GENDER, gender);

    // this works if the value is false but does not if it is true

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

    _record.set_Fields(ERECORDSFields.RECORDS_fld_KEY_INDICATOR, "I"); _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_PRIMARY_ADDRESSEE_ID, "1");

    _record.set_Fields(ERECORDSFields.RECORDS_fld_PRIMARY_SALUTATION_ID, "16");

    _record.set_Fields(ERECORDSFields.RECORDS_fld_PRIMARY_ADDRESSEE_EDIT, "false");

    //_record.set_Fields(ERECORDSFields.RECORDS_fld_PRIMARY_ADDRESSEE, "-");

    _record.set_Fields(ERECORDSFields.RECORDS_fld_PRIMARY_SALUTATION_EDIT, "false");

    //_record.set_Fields(ERECORDSFields.RECORDS_fld_PRIMARY_SALUTATION, "mr");

    if (deceasedDate.HasValue)

    {

    _record.set_Fields(
    ERECORDSFields.RECORDS_fld_DECEASED_DATE, deceasedDate.Value);_record.set_Fields(ERECORDSFields.RECORDS_fld_DECEASED, "1");

    }

    _record.Save();

    }

    finally

    {

    _record.CloseDown();

    System.Runtime.InteropServices.
    Marshal.ReleaseComObject(_record);

    }

    Filed under: ,
  • 06-20-2008 12:20 AM 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

    Ok I have it finally working! The main thing to check for is to go via the RE client into Config -> Fields and check whether all fields, that are marked as required, are provided for in the code. If any of those fields are missing, the API will throw up an error. Upon looking at the exception, the Source property will tell you which object the error applies to. In my case, it was CProspect. Hence I gave Prospect a value and it worked!

    Filed under: ,
  • 06-20-2008 12:22 AM In reply to

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

    Solved

    Ok I have it finally working!

    The main thing to check for is to go via the RE client into Config -> Fields and check whether all fields, that are marked as required, are provided for in the code. If any of those fields are missing, the API will throw up an error.

    Upon looking at the exception, the Source property will tell you which object the error applies to. In my case, it was CProspect. Hence I gave Prospect a value and it worked!

    Filed under: ,
  • 06-20-2008 3:15 AM In reply to

    • David Zeidman
    • Top 25 Contributor
    • User Since: 2002
    • Posts 326
    • Organization: Zeidman Development
    • Products:  Blackbaud Direct Marketing, Blackbaud Enterprise CRM, The Information Edge, The Raiser's Edge

    Re: Solved

     Good to hear that you have it working. The constituent table is used by RE for looking up constituents. It stores each constituent, each spouse of each constituent and aliases so that when you use the constituent search screen RE can find the constituent you are looking for without referencing loads of tables. I suspect that it worked when you entered is_constituent = false because non-constituents do not have the prospect module and your mandatory field there would not be affected. However I am not quite sure where this non-constituent would have appeared in RE. This flag is used in the records table to indicate which entries are constituents and which are relationships. Given that they were neither it is unlikely they would appear in the GUI.

    David

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

    Check out my RE API blog
    http://www.re-decoded.com
Page 1 of 1 (8 items)