Command returning all Application Currencies

AndreaF
Contributor III

Hi,

is there an BrApi command that returns the Application Currencies, ideally as a list of strings?

AndreaF_2-1700760284102.png

I would like to use the output, i.e. the list of currencies, in an Extender business rule, where I need to loop through them.

Thank you

 

1 ACCEPTED SOLUTION

JackLacava
Community Manager
Community Manager

BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter. Manipulate it with StringHelper.SplitString to get it as a List of String objects.

View solution in original post

7 REPLIES 7

MarkBird
Contributor II

Hi Andrea

I couldn't see a BRApi function that would get you this list - hopefully someone else can, but failing that you can query the AppProperty table to get the list. 

Below is a snippet of code (VB.NET) that will give you what you need:

Using dbConn As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
	'Query the App Property table to get the currency list
	Dim sCurrencyFilter As String = BRApi.Database.ExecuteSql(dbconn, "SELECT Top 1 TextValue FROM AppProperty WHERE Name = 'CurrencyFilter'", False).Rows(0)(0)
	
	'Split currency string into array of currencies
	Dim currencies As String() = sCurrencyFilter.Split(New String() {", "}, StringSplitOptions.None)
	
	'Loop through each currency
	For Each curr In currencies
		'Get currency object using currency name
		Dim objCurrency As Currency = BRApi.Finance.Cons.GetCurrency(si, curr)

		'Do what you like with the currency...
		BRApi.ErrorLog.LogMessage(si, curr)
	Next
End Using

Regards,

Mark

JackLacava
Community Manager
Community Manager

BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter. Manipulate it with StringHelper.SplitString to get it as a List of String objects.

AndreaF
Contributor III

Thank you both for your help!

I would have expected to see it in the formula helper panel, but maybe BrApi.Utilities is not included in there

 

AndreaF_0-1700819246787.png

 

It's there, but the helper tree can only go 2 levels deep. So you will find Brapi.Utilities.GetApplicationProperties, and if you select that and look at the Objects tab, you'll find the AppProperties object - click on it and you'll get its methods and properties, including CurrencyFilter.

Jack, that is brilliant. I never knew that you could click on the objects...

I used to scroll through intellisense.

MarkBird_0-1700820157606.png

 

Yeah, that opens a world 😉 happy digging!

sameburn
New Contributor III

Hi Andrea

You can use this approach also (if only interested in C#Currencies.Children) e.g. 

Dim sb As New Text.StringBuilder	
' Get Currencies
Currency.GetItems().ForEach(Sub(lambda) sb.AppendLine(String.Format("Name -> {0}, Id -> {1}", lambda.Name, lambda.Id)))						
' Log Result -> Throw Error
BRApi.ErrorLog.LogMessage(si, "Currency Output", sb.ToString)