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 Codeat 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?
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
I tried removing the CONSTITUENT_CODE_fld_CONSTIT_ID assignment but I get this error:
System.Runtime.InteropServices.COMException (0x80040666): Required Field Missing: Statusat BBREAPI7.CRecordClass.Save()
I did some more investigation yesterday and discovered that if I set:
_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
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.