Start a new topic

Deleting Aliases

Has anyone already written code to globally delete an alias based on type (type and name)? We have lots of old ones that I'd like to get clean-up.

I'd be interested in any alias-related API.


Hi Barabara,

 

It turns out I was on this site recently looking for some sample code for a similar purpose and ended up writing my own. I can't guarantee my syntax is best practice, however, it does work. You will also want to test, test, test. Alias is a collection and so you will not have a 'Load' method, therefore this code will cycle through each alias record and find the one you want by using criteria (e.g. if the alias name = '123456'). You can also update Alias Types and Values by setting the values (I added a row of code for each of these below as an example). This code should go in the "BeforeConstituentSave" Public Override Sub. Also, don't forget to add the import references at the top of your API code (e.g. "Imports Blackbaud.PIA.RE7.BBREAPI")

 

 

Dim oAlias As BBREAPI.CAlias

Dim ConsID As String = Import.Fields.GetByName("Consid").Value

For Each oAlias In oRec.Aliases

If oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_KEY_NAME)=ConsID Then

If oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_ALIAS_TYPE)="Convio Constituent ID" Then

'If you want to remove the Alias

oRec.Aliases.Remove(oAlias)

 

'If you want to update the Alias Type

oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_ALIAS_TYPE)="Luminate ID"

 

'If you want to update the Alias Name (value)

oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_KEY_NAME)="12345"

End If

End If

Next oAlias

 

Grant 

 

 


1 person likes this
That's great code, Grant. Thanks!
I was hoping to adapt it for a problem I'm having. There are some blank rows in the alias field. I suspect this was caused by importing into the alias field with no values included. These need to be deleted before we can manually add and save and alias, so it's a bit of a pain. I'm having trouble figuring out how to delete the rows when there's no alias type to reference. Any thoughts on how to solve that?
Thanks in advance.

Gregg
Thank you Grant! I'll play around with your code and see how it works for my project. Gregg, we have some blank alias rows as well. If I get closer with that, I'll update here.

-Barbara
Thanks for sharing this code. I was able, through trial and error, to add in the code to remove the alias without errors in the code. However, I'm not sure how I would set up my file/columns. Right now, I have an alias of Patient ID that is the same as the Constituent ID. So I have the same value in both places, incorrectly. I'm wanting to delete the alias all together, but when I tested this code on 1 record, it runs fine, but the alias and value are still there. My file contains 2 columns, ConsID and Patient ID, and is mapped to Constituent ID and Alias Match or Add. (the same thing happens if I am mapped to Alias Add.

I'm very unfamiliar with code. And my logic is way off in my brain. What fields in the import file do I need or am I mapping incorrectly? Any thoughts would be greatly appreciated.

Melissa
Thanks for sharing this code. I was able, through trial and error, to add in the code to remove the alias without errors in the code. However, I'm not sure how I would set up my file/columns. Right now, I have an alias of Patient ID that is the same as the Constituent ID. So I have the same value in both places, incorrectly. I'm wanting to delete the alias all together, but when I tested this code on 1 record, it runs fine, but the alias and value are still there. My file contains 2 columns, ConsID and Patient ID, and is mapped to Constituent ID and Alias Match or Add. (the same thing happens if I am mapped to Alias Add. 

I'm very unfamiliar with code. And my logic is way off in my brain. What fields in the import file do I need or am I mapping incorrectly? Any thoughts would be greatly appreciated. 

Melissa

Hi,

 

I included a row of sample code in my original post that will remove an alias record: "oRec.Aliases.Remove(oAlias)"

If you include this line after you select your alias record via criteria (if Alias=1234 then), it should remove it. Remember that when you are using criteria to select a specific alias record, the selected alias record is represented in the code by 'oAlias.' Also, if your Constituent ID and Alias name (ID) is always the same, you could use one column in your profile (Constituent ID) and use it to match to both the constituent record and then the alias record you want to delete. 


Example:


'look through each alias on the constituent

For Each oAlias In oRec.Aliases

 

'find an alias on the constituent where the alias = consid ('1234') and the alias type = 'convio constituent ID'

If oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_KEY_NAME)=ConsID Then

If oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_ALIAS_TYPE)="Convio Constituent ID" Then

 

'remove the matched alias record (alias = 1234, alias type = 'convio constituent id')

oRec.Aliases.Remove(oAlias)

 

End If

End If

Next oAlias 


Grant

I finally got around to this project. Here’s what I finally ended up with in case someone else is trying to do something similar. My goal was to delete old/unused aliases from constituent records.


My import file has the following fields (mapping):

A: ConsID (mapped to ConsID)

B: ImportID (Ignore)

C: AliasType (Ignore)

D: Alias (Ignore)


I want the IOM Profile to delete any aliases where the type and alias match the incoming record.


1st line in Code: Imports Blackbaud.PIA.RE7.BBREAPI


After "Public Class Profile Inherits ImportOM.API.ProfileBase" (before Public Overrides):

Public function GetColumn(ColumnName As String) As String

GetColumn = Import.Fields.GetByExcelName(ColumnName).Value

End function

End sub


In BeforeConstituentSave section:

'This starts the section to remove matching Aliases

Dim oAlias As Blackbaud.PIA.RE7.BBREAPI.CAlias

Dim sAliasType="C"

Dim sAlias="D"

'look through each alias on the constituent

For Each oAlias In oRec.Aliases

'find an alias on the constituent where the alias type matches incoming remove the alias

If oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_ALIAS_TYPE)=GetColumn(sAliasType) And oAlias.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENTFields.ALIAS_fld_KEY_NAME)=GetColumn(sAlias)Then

oRec.Aliases.Remove(oAlias)

End If

Next oAlias

End Sub




1 person likes this
Login or Signup to post a comment