Start a new topic

How do I use an import to change an email or phone type

Please excuse the double post-- I'm asking one question, but it has multiple parts, and doesn't neatly fit into one category or the other.

 

 

There was an old thread here: Make Phone/Email Primary 

that I commented on 9 days ago.


 

It had a large pile of custom code, which I was mostly able to implement to solve the problem of not being able to change email type in an import. But apparently the way to reference the phones grid for get() is different than the way you have to reference it for set(), and I don't have enough of a background in object oriented programming or specifically "Reflection" to figure it out without a pretty direct code sample I can copy and paste.

 

-------- 

I'm hoping someone can help me with solution(s) to this problem because being able to programmatically update email type is going to be key to our automating what is now a very manual process we have to perform on every record that comes in from Luminate Online.


Isaac, can you post the current version of your code so all can review to possible assist. Thanks

At the moment, all I have is code that gets info from the phones grid for the current constituent being processed, and if the phone type is "Primary email", it outputs what it finds to a file.


There's a couple experimental lines:

  Dim SetMethod As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("set_Phones")

  Dim SetPhones = method.Invoke(oRec, Nothing)


But they're not tied to anything else atm.  I'm not sure how to come up with an equivalent to, e.g.:

Dim phoneType = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {2}) 

but for writing to the phones grid instead of reading from it.  When I tried taking a couple guesses at it, not surprisingly I received "Object or With block not set error"

But, from the old thread I previously referenced: 
Make Phone/Email Primary, I know that other people have been able to get it to work.  Unfortunately, the code they actually came up with is not in the chat.


   

Public Class Profile
    Inherits ImportOM.API.ProfileBase

	Dim FileN As String= "W:\Philanthropy\Database\OmaticOutput\OutputPhoneDetails."
		
	Dim objWriter As New System.IO.StreamWriter(FileN & DateTime.Now.ToString("yyyyMMddHHmmssFFF") & ".csv")

    Public Overrides Sub BeforeConstituentSave(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, _
                                        Cancel as ImportOM.API.iCancel)
        'The main constituent record is about to be saved
       ' Const Rec_fld_NoEmail as long = 79
		'orec.Fields(Rec_fld_NoEmail) = False
		
		Dim method As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("get_Phones") 
		Dim phones = method.Invoke(oRec, Nothing) 
		
		Dim SetMethod As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("set_Phones")
		Dim	SetPhones = method.Invoke(oRec, Nothing)

		Dim iPhoneCount As Integer = phones.GetType().GetMethod("Count").Invoke(phones, Nothing) 
		
		Dim TextLine As String
		
		For i As Integer = 1 To iPhoneCount 

		Dim phone = phones.GetType.GetMethod("Item").Invoke(phones, New Object() {i}) 
		Dim someID = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {1}) 
		Dim phoneType = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {2}) 
		Dim phoneNum = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {3}) 
		Dim shareStatus = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {4}) 
		Dim unknownFlag = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {5}) 
		Dim brace6 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {6}) 
		Dim brace7 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {7}) 
		Dim brace8 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {8}) 
		Dim brace9 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {9}) 
		Dim brace10 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {10}) 
		Dim brace11 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {11}) 
		Dim brace12 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {12}) 
		Dim brace13 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {13}) 
		Dim brace14 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {14}) 
		Dim brace15 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {15}) 
		Dim brace16 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {16}) 
		Dim brace17 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {17}) 
		Dim brace18 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {18}) 
		Dim brace19 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {19}) 
		Dim brace20 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {20}) 
		
			TextLine = ("" & someID & ", " & phoneType & ", " & phoneNum & ", " & shareStatus & ", " & unknownFlag & ", " & _
			     brace6 & ", " & brace7 & ", " & brace8 & ", " & brace9 & ", " & brace10 & ", " & brace11 & ", " & brace12 & ", " & _
			     brace13 & ", " & brace14 & ", " & brace15 & ", " & brace16 & ", " & brace17 & ", " & brace18 & ", " & brace19 & _
			      ", " & brace20 ) 
			      
			If phoneType = "Primary email" Then objWriter.WriteLine(TextLine)     
		Next i 
    
    
    End Sub
 
End Class

   

(Hopefully, the post goes through this time-- last time it seems to have not posted.)

At the moment, all I have is code that gets info from the phones grid for the current constituent being processed, and if the phone type is "Primary email", it outputs what it finds to a file.

 

 

There's a couple experimental lines:

 

  Dim SetMethod As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("set_Phones")

 

  Dim SetPhones = method.Invoke(oRec, Nothing)

 

 

 

But they're not tied to anything else atm. I'm not sure how to come up with an equivalent to, e.g.:

Dim phoneType = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {2})

 

but for writing to the phones grid instead of reading from it. When I tried taking a couple guesses at it, I got the error "Object or With block not set."

This is what I had tried:

Dim phoneSetField = phone.GetType.GetMethod("set_Fields", New Type(){GetType(Integer), GetType(Object)})

    Dim retVal1 = phoneSetField.Invoke(phone, New Object() {2, "<set phone type here>"})

This is my current code:

 

Public Class Profile
    Inherits ImportOM.API.ProfileBase

	Dim FileN As String= "W:\Philanthropy\Database\OmaticOutput\OutputPhoneDetails."
		
	Dim objWriter As New System.IO.StreamWriter(FileN & DateTime.Now.ToString("yyyyMMddHHmmssFFF") & ".csv")

    Public Overrides Sub BeforeConstituentSave(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, _
                                        Cancel as ImportOM.API.iCancel)
        'The main constituent record is about to be saved
       ' Const Rec_fld_NoEmail as long = 79
		'orec.Fields(Rec_fld_NoEmail) = False
		
		Dim method As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("get_Phones") 
		Dim phones = method.Invoke(oRec, Nothing) 
		
		Dim SetMethod As System.Reflection.MethodInfo = oRec.GetType().GetMethod ("set_Phones")
		Dim	SetPhones = method.Invoke(oRec, Nothing)

		Dim iPhoneCount As Integer = phones.GetType().GetMethod("Count").Invoke(phones, Nothing) 
		
		Dim TextLine As String
		
		For i As Integer = 1 To iPhoneCount 

		Dim phone = phones.GetType.GetMethod("Item").Invoke(phones, New Object() {i}) 
		Dim someID = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {1}) 
		Dim phoneType = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {2}) 
		Dim phoneNum = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {3}) 
		Dim shareStatus = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {4}) 
		Dim unknownFlag = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {5}) 
		Dim brace6 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {6}) 
		Dim brace7 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {7}) 
		Dim brace8 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {8}) 
		Dim brace9 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {9}) 
		Dim brace10 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {10}) 
		Dim brace11 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {11}) 
		Dim brace12 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {12}) 
		Dim brace13 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {13}) 
		Dim brace14 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {14}) 
		Dim brace15 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {15}) 
		Dim brace16 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {16}) 
		Dim brace17 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {17}) 
		Dim brace18 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {18}) 
		Dim brace19 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {19}) 
		Dim brace20 = phone.GetType.GetMethod("get_Fields",New Type() {GetType(Integer)}).Invoke(phone, New Object() {20}) 
		
			TextLine = ("" & someID & ", " & phoneType & ", " & phoneNum & ", " & shareStatus & ", " & unknownFlag & ", " & _
			     brace6 & ", " & brace7 & ", " & brace8 & ", " & brace9 & ", " & brace10 & ", " & brace11 & ", " & brace12 & ", " & _
			     brace13 & ", " & brace14 & ", " & brace15 & ", " & brace16 & ", " & brace17 & ", " & brace18 & ", " & brace19 & _
			      ", " & brace20 ) 
			      
			If phoneType = "Primary email" Then objWriter.WriteLine(TextLine)     
		Next i 
    
    
    End Sub
 
End Class
   

 

Login to post a comment