Forum Discussion
AndreaF
2 years agoContributor III
Command returning all Application Currencies
Hi,
is there an BrApi command that returns the Application Currencies, ideally as a list of strings?
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
BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter. Manipulate it with StringHelper.SplitString to get it as a List of String objects.
9 Replies
- JackLacava
OneStream Employee
BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter. Manipulate it with StringHelper.SplitString to get it as a List of String objects.
- binepalNew Contributor
Hi Jack, I need this list but can't use the split string, let alone get it to display. I've tried different permutations, checked articles and tested examples that use other approaches. Can you please tell me where I'm going wrong?
Dim appCurrencies As String = _ BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter.ToString Dim strCurrencies As List(Of String) = StringHelper.SplitString(appCurrencies, ",", _ StageConstants.ParserDefaults.DefaultQuoteCharacter) Brapi.ErrorLog.LogMessage(si, "appCurrenciesDisplay: " & appCurrenciesDisplay) '-- works Brapi.ErrorLog.LogMessage(si, "strCurrencies: " & strCurrencies.toString) '--doesn't work- binepalNew Contributor
Please ignore, worked it out. Thank you for your posts, Jack.
- MarkBirdContributor III
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 UsingRegards,
Mark
- AndreaFContributor 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
- JackLacava
OneStream Employee
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.
- MarkBirdContributor III
Jack, that is brilliant. I never knew that you could click on the objects...
I used to scroll through intellisense.
- sameburn
OneStream Employee
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)
Related Content
- 2 years ago