Forum Discussion
Richard_Mayo
2 years agoNew Contributor III
Where text field is not blank (data buffer)
Good morning all!
I'm hoping somebody can put me on the right path...!
I'm writing a rule with a data buffer. I want to filter the data buffer so it only runs where needed.
I put in the followi...
- 2 years ago
I see. Yeah my version is probably a bit more efficient. The other bit I would try to optimize is the lookup of the Text variable, with some sort of dictionary acting as a cache - so that we do the actual lookup only once. Roughly:
' outside the loop. Dim AccTextCache as new Dictionary(Of Integer, String) For each cell in yourBuffer ' If you've not filtered your buffer already to contain only interesting cells, ' do your work here, then... ' try to get text from cache Dim accText as String = AccTextCache.XFGetValue(cell.DataBufferCellPK.AccountID, Nothing) if accText is Nothing then ' not found in cache, need to look it up ... ' note: prefer api. methods over brapi. ones, they are faster accText = api.Account.Text(cell.DataBufferCellPK.AccountID, 6, scenarioTypeId, timeId) ' ... then store it in our cache AccTextCache.Add(cell.DataBufferCellPK.AccountID, accText) end if ' rest of the work here next... but the value of this effort may or may not be significant, only benchmarking would tell.
I'd also try to get rid of any call to .GetAccountName and similar. Stick to IDs everywhere.
Richard_Mayo
2 years agoNew Contributor III
Thanks so much Jack for putting that example in, I really appreciate it. Also Robb, cheers for the input. (Weirdly the screenshot looks like a gap between apostrophes but actually there wasn't. In any case sounds like that filtering option won't work, but thanks for the suggestion.)
Jack - I'll try your idea. In the meantime I came up with a workable solution though I'm sure it's not as efficient as yours!
Basically I created a bigger source data buffer to start with (as I can't filter on it directly) (STEP 1)
Then for each cell in the data buffer I pull back the Text6 value (STEP 2)
Then I use a simple if statement to say if it's blank, do nothing, if it holds something then proceed to the calc and result buffer (STEP 3).
Like I say, probably not as efficient as your version but it's a similar logic so at least I'm on the right lines...!
FYI - the reason I'm doing it like this is because I need to pull data in the source buffer but then use the dimensionality (plus text fields) in order to drive the result cells. I didn't think I could get this working with a standard api.data.calculate.
Anyway, thanks again for the time and support, much appreciated.
JackLacava
OneStream Employee
2 years agoI see. Yeah my version is probably a bit more efficient. The other bit I would try to optimize is the lookup of the Text variable, with some sort of dictionary acting as a cache - so that we do the actual lookup only once. Roughly:
' outside the loop.
Dim AccTextCache as new Dictionary(Of Integer, String)
For each cell in yourBuffer
' If you've not filtered your buffer already to contain only interesting cells,
' do your work here, then...
' try to get text from cache
Dim accText as String = AccTextCache.XFGetValue(cell.DataBufferCellPK.AccountID, Nothing)
if accText is Nothing then
' not found in cache, need to look it up ...
' note: prefer api. methods over brapi. ones, they are faster
accText = api.Account.Text(cell.DataBufferCellPK.AccountID, 6, scenarioTypeId, timeId)
' ... then store it in our cache
AccTextCache.Add(cell.DataBufferCellPK.AccountID, accText)
end if
' rest of the work here
next
... but the value of this effort may or may not be significant, only benchmarking would tell.
I'd also try to get rid of any call to .GetAccountName and similar. Stick to IDs everywhere.
- Richard_Mayo2 years agoNew Contributor III
Thanks again Jack - much appreciated (sorry been out of office hence slow response but I appreciate your example and explanation which I'll work with.)
Related Content
- 3 years ago
- 2 years ago