Get Account Type as Integer From String

Keyser_Soze
New Contributor III

Hello There,

Is there a way to get the 'Integer' behind each Account Type based on a 'String' ?

Context: I am trying to create new Account Members with pre-defined properties, all properties were straightforward except for the account type. Below a code portion for modifying a property & a hardcoded solution:

myaccountMember = BRApi.Finance.Metadata.GetMember(si, DimTypeId, accountID, True)	
						
Dim AccProperties As AccountVMProperties = myaccountMember.GetAccountProperties()
'Add AccountProperties
    '*** Text123 ***							 
    AccProperties.Text1.SetStoredValue(ScenarioType.Unknown.Id,DimConstants.Unknown, mytxt1)
							 
    AccProperties.Text2.SetStoredValue(ScenarioType.Unknown.Id,DimConstants.Unknown, mytxt2)
							 
    AccProperties.Text3.SetStoredValue(ScenarioType.Unknown.Id,DimConstants.Unknown, mytxt3)
    
    '*** AllowInput ***							 
    AccProperties.AllowInput.SetStoredValue(Boolean.Parse(isAllowInput))
    
    '*** Account Type ***
    Dim accTypeInt As Integer = GetAccountType(si, accountType)	' Since the 'SetStoredValue() only takes integers, I had to create a separate function that retrieves it						 
    AccProperties.AccountType.SetStoredValue(accTypeInt) 

Here is the hardcoded function 'GetAccountType'() :

Public Function GetAccountType(ByVal si As SessionInfo, ByVal AccountType As String) As Integer
			Try
				Select Case AccountType 'Revenue, Expense, Asset, Liability, Flow, Balance, BalanceRecurring, NonFinancial, DynamicCalc, Group
					Case = "Revenue"
						Return 1
					Case = "Expense"
						Return 2
					Case = "Asset"
						Return 3
					Case = "Liability"
						Return 4
					Case = "Flow"
						Return 5
					Case = "Balance"
						Return 6
					Case = "BalanceRecurring"
						Return 7
					Case = "NonFinancial"
						Return 8
					Case = "DynamicCalc"
						Return 9
					Case Else
						Return 0
				End Select			
				
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function

 

1 ACCEPTED SOLUTION

JackLacava
Community Manager
Community Manager

Off the top of my head:

Function GetAccountTypeByName(ByRef accTypeName as String)
	try:
		return AccountType.GetItem(accTypeName)
	catch ex as Exception:
		throw ErrorHandler.LogWrite(si, new XFException(si, ex))
	end try
end function

That gives you back an AccountType object, which is a bit more flexible. Then in your main code you can use it like this:

 AccProperties.AccountType.SetStoredValue( GetAccountTypeByName("Flow").Id )

 

View solution in original post

4 REPLIES 4

JackLacava
Community Manager
Community Manager

Off the top of my head:

Function GetAccountTypeByName(ByRef accTypeName as String)
	try:
		return AccountType.GetItem(accTypeName)
	catch ex as Exception:
		throw ErrorHandler.LogWrite(si, new XFException(si, ex))
	end try
end function

That gives you back an AccountType object, which is a bit more flexible. Then in your main code you can use it like this:

 AccProperties.AccountType.SetStoredValue( GetAccountTypeByName("Flow").Id )

 

Ingenious as usual ! Thanks

RobbSalzmann
Valued Contributor

Hi @Keyser_Soze ,
Using your code above, it can be as simple as:

dim acctTypeId = BRApi.Finance.Account.GetAccountType(si, accountId).Id

 

Oops, I see you're creating members.  Agree with @JackLacava :

Dim acctTypeId as Integer = AccountType.GetItem(accTypeName).Id