Start a new topic

Lookup by Action Type

Hello, 

I am hoping someone can point me in the right direction.

I would like to use the API to do a lookup to check if a constituent has an action record with a specific type. The purpose of this lookup is to prevent IOM from adding a second action of the same type if it is already present on the constituent. 

Thank you in advance!

Grant    


Hi Grant,

Test this.

You have to put it into the After Dictionary Event or something similar. So it gets processed before IOM attempts to save it.


[code] Dim oRec as New Blackbaud.PIA.RE7.BBREAPI.CRecord Dim oAction as Blackbaud.PIA.RE7.BBREAPI.CAction Dim sConstitID as String = 1 oRec.Init(Import.SessionContext) oRec.LoadbyField(Blackbaud.PIA.RE7.BBREAPI.bbRecordUniquefields.uf_Record_Constituent_ID, sConstitID ) For Each oAction in oRec.Actions If oAction .Fields(Blackbaud.PIA.RE7.BBREAPI.EActionFields.Action_fld_type) = "XXX" Then 'Set all Action Fields in the Import file to "" Import.Fields.GetByName("XXXXX").Value = "" Import.Fields.GetByName("XXXXX").Value = "" Import.Fields.GetByName("XXXXX").Value = "" End if Next oAction oAction = nothing oRec.CloseDown oRec = Nothing [/code]


Hope this helps
There is actually a hook for AfterConstituentOpen

Just type "Public Overrides" in the editor and a list will come up and you can select AfterConstituentOpen. Then you already have the correct constituent record and you can mess with it before anything is saved!

Hello Philip, 

Thank you for the code, I have successfully tested it. This was immensely helpful!! I do have a couple of follow-up questions about your code sample, if you don't mind.

1. The code you provided requires the ConstitID to be provided in the import file, can the code be modified to pass the constituent ID of the record IOM matches during the matching process?

2. I got the code to work eventually, but my initial approach didn't. What I attempted to do, at first, was modify your code to include an else statement and map the data in code (I have put it in italics). Therefore, if the action type does exist the data should be ignored, otherwise IOM should import the data as a new record. For some reason (probably a mistake on my part!), IOM added the Action Type even though it already existed on the Constituent. Why? 

'Lookup Action Type to find Vol-Volunteer Record
Dim oRec as New  Blackbaud.PIA.RE7.BBREAPI.CRecord

Dim oAction as Blackbaud.PIA.RE7.BBREAPI.CAction

Dim sConstitID As String =  Import.Fields.GetByName("Constituent ID").Value

oRec.Init(Import.SessionContext)
oRec.LoadbyField(Blackbaud.PIA.RE7.BBREAPI.bbRecordUniquefields.uf_Record_Constituent_ID, sConstitID)

For Each oAction In oRec.Actions 

If oAction .Fields(Blackbaud.PIA.RE7.BBREAPI.EActionFields.ACTION_fld_TYPE)= "XXX" Then

'Set all Action Fields in the Import file to ""
Import.Fields.GetByName("Action Type").Value=""
Import.Fields.GetByName("Action Date").Value=""
Import.Fields.GetByName("Action Status").Value=""
Import.Fields.GetByName("Action Category").Value=""
Import.Fields.GetByName("Action Attr Desc 1").Value="" 

Else 
Import.Fields.GetByName("Action Type").Value="XXX"
Import.Fields.GetByName("Action Date").Value="01/01/2013"
Import.Fields.GetByName("Action Status").Value="Open"
Import.Fields.GetByName("Action Category").Value="Task/Other"
Import.Fields.GetByName("Action Attr Desc 1").Value=Import.Fields.GetByName("YYY").Value


End if

Next oAction 


oAction = nothing
oRec.CloseDown
oRec = Nothing

Thanks again!!

Grant   

Wayne,

Thank you for your response. If I place the code in the Public Override AfterConstituentOpen can I forego providing the Constituent ID (ie. by this point IOM will have matched on a record using its own match functionality)? 

Thanks, 

Grant

Grant,
You are welcome! You can follow Wayne's suggestion but it might not work the way I coded (Setting the Import field = "") but you can test it. Yes, you do not have to provide the ID... but how are you mapping it int he front end so that IOM can find the right record? I have modified it for you below:

[Code] Dim oAction as Blackbaud.PIA.RE7.BBREAPI.CAction Dim sConstitID as String = 1 For Each oAction in oRec.Actions If oAction .Fields(Blackbaud.PIA.RE7.BBREAPI.EActionFields.Action_fld_type) = "XXX" Then 'Set all Action Fields in the Import file to "" Import.Fields.GetByName("XXXXX").Value = "" Import.Fields.GetByName("XXXXX").Value = "" Import.Fields.GetByName("XXXXX").Value = "" End if Next oAction oAction = nothing [/Code]

On your second question: Did you map the action record in the front end? This will import the action record. Also I do not quite understand why you included the If Else End If statement? Is that Data not in the import file already? Or do you just have blank fields? If you want to truly "Map your file in code" than that requires some more coding to add the entire Action Record in Code and then save it. But maybe I do not understand exactly what you are trying to solve.


Here is another tip which I am using liberally: msgbox("Now I am in xxx part of the code: sSomeVariable has currently the following value: " & sSomeVariable )

This is a replacement of sorts for the Debug.Print option in VB6 and helps track your code.

Philip,

Thank you for following-up. Perhaps I should have given you more details before asking questions! 

Question 1:

Your 'test' code passes a string value ("1") as the constituent ID. I added a constituent ID column to my file and referenced it (import.fields.getbyname) instead of "1" so that I could use some real examples in our database. However, I would like IOM to be able to match to an existing constituent (using its standard matching functionality) if an ID is not present in the file. Once it matches on a constituent, then do the Action lookup. The reason for this is the data files the profile will eventually process may only have bio info, but no ID. 

Question 2:

Currently I have mapped some of the file's fields in the "front end" mapping section and the rest in virtual fields (the profile currently works). However, originally, I attempted to map everything using virtual fields (ie. "Action Type") and then reference them in the code as needed (Import.Fields.GetByName("Action Type").Value="XXX"). Other fields, such as an action attribute, had values in the data file ("Action Subtype") but I created a virtual field ("SubType") and referenced them in code instead of mapping the fields in the "front end" (ie. Import.Fields.GetByName("Subtype").Value=Import.Fields.GetByName("Action SubType").Value). I added an Else statement because if the first condition is not met (Action Type ="xxx" does not exist) then I wanted to add Action Type = "xxx" on the Constituent's record. This initial approach resulted in IOM adding the Action Type regardless of whether the first IF statement was true or false, I was only curious why.

Thanks!

Grant  

Hello Grant,

A couple of suggestions here.

1) At the very top of your code you can put the line [code]Imports Blackbaud.PIA.RE7.BBREAPI [/code] which will allow you to just use the field references.
ex. [code]EActionFields.ACTION_fld_TYPE[/code] instead of [code]Blackbaud.PIA.RE7.BBREAPI.EActionFields.ACTION_fld_TYPE[/code]

2) Using the AfterConstituentOpen will automatically give you the record of the matched constituent so you should just include the ID (or criteria to match) in your import file.

3) The reason you are getting the action created anyways is because your action code is happening <i>for each action on the record</i> instead of just being on or off for the whole record. I would suggest that you use the [code]Exit For [/code] command to break out of the loop once you have found the right action (or keep running until the end if you never find it).

Try this out:
[code] '!!This line goes at the very top of your .vb file!! Imports Blackbaud.PIA.RE7.BBREAPI '... ' Add the AfterConstituentOpen hook ' Just start typing "Public Overrides" and it should show up Public Overrides Sub AfterConstituentOpen(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, ByVal Cancel As ImportOM.API.iCancel) 'Lookup Action Type to find Vol-Volunteer Record Dim oAction as Blackbaud.PIA.RE7.BBREAPI.CAction Dim bTypeExists as Boolean ' For each action, check if type XXX exists ' Note that in AfterConstituentOpen oRec is already initiated with the matched (or created!) constituent. For Each oAction In oRec.Actions 'If the action type was found set the flag and exit the loop, else keep looking If oAction .Fields(EActionFields.ACTION_fld_TYPE)= "XXX" Then 'Set the flag bTypeExists = True ' Exit the loop now that we have found it Exit For Else 'You probably just want to set the default action values in virtual fields so you don't have to do anything here. 'Otherwise you can hard code them like you did before as below 'Import.Fields.GetByName("Action Type").Value="XXX" 'Import.Fields.GetByName("Action Date").Value="01/01/2013" 'Import.Fields.GetByName("Action Status").Value="Open" 'Import.Fields.GetByName("Action Category").Value="Task/Other" 'Import.Fields.GetByName("Action Attr Desc 1").Value=Import.Fields.GetByName("YYY").Value End If Next oAction 'If you found the type in the list of actions then don't import it If bTypeExists 'Set all Action Fields in the Import file to "" Import.Fields.GetByName("Action Type").Value="" Import.Fields.GetByName("Action Date").Value="" Import.Fields.GetByName("Action Status").Value="" Import.Fields.GetByName("Action Category").Value="" Import.Fields.GetByName("Action Attr Desc 1").Value="" End if oAction = nothing End Sub [/code]
well, that was really ugly, but the actual code came out at the end so you should be able to use that.

Hi Wayne, 

Thank you for your suggestion. I will look through your code and do some testing.

Your help is appreciated!

Grant

Login or Signup to post a comment