10-19-2021 01:25 PM - last edited on 05-25-2023 07:38 AM by JackLacava
Hi all
What is the globals object good for we are seeing in all the business rules?
Solved! Go to Solution.
10-19-2021 02:09 PM
With the globals variable, you can store data or objects globally and transfer it from one process steps to another.
This is a sample how to count process steps
Dim aSimpleCounter As Integer
'lock the process to avoid overrides
SyncLock Globals.LockObjectForInitialization
'Initialize aSimpleCounter with the stored variable, or initialize it with 0
simpleCounter = globals.GetInt32Value("SimpleCounter", 0)
'Count it up by 1
simpleCounter +=1
'Save it to globals
globals.SetInt32Value("SimpleCounter", simpleCounter)
End SyncLock
You can also store objects like list or dictionaries in globals
Dim nameToStore As String = "MyObjectName"
'Definition of a list
Dim anyObject As list(of string)
'lock the process to avoid multiple initialisations
SyncLock Globals.LockObjectForInitialization
'Check if the object is already stored in globals
anyObject = globals.GetObject(nameToStore)
'If not initialize it
If anyObject Is Nothing Then
'create and populate the list
anyObject = New list(of string)
anyObject.add("One")
anyObject.add("Stream")
anyObject.add("Software")
globals.SetObject(nameToStore , anyObject)
End If
End SyncLock
'Continue working
Be careful, many object like list and dictionaries are not supporting mutithreaded (support working in parallel), so you can not use them to add members to the list during a report or a consolidation.
But there are multithreaded versions you can use for this purpose
'Additional Imports for concurent list and dictionary
Imports System.Collections.Concurrent
'create a concurrent dictionary
Dim concDict As New ConcurrentDictionary()
10-19-2021 02:09 PM
With the globals variable, you can store data or objects globally and transfer it from one process steps to another.
This is a sample how to count process steps
Dim aSimpleCounter As Integer
'lock the process to avoid overrides
SyncLock Globals.LockObjectForInitialization
'Initialize aSimpleCounter with the stored variable, or initialize it with 0
simpleCounter = globals.GetInt32Value("SimpleCounter", 0)
'Count it up by 1
simpleCounter +=1
'Save it to globals
globals.SetInt32Value("SimpleCounter", simpleCounter)
End SyncLock
You can also store objects like list or dictionaries in globals
Dim nameToStore As String = "MyObjectName"
'Definition of a list
Dim anyObject As list(of string)
'lock the process to avoid multiple initialisations
SyncLock Globals.LockObjectForInitialization
'Check if the object is already stored in globals
anyObject = globals.GetObject(nameToStore)
'If not initialize it
If anyObject Is Nothing Then
'create and populate the list
anyObject = New list(of string)
anyObject.add("One")
anyObject.add("Stream")
anyObject.add("Software")
globals.SetObject(nameToStore , anyObject)
End If
End SyncLock
'Continue working
Be careful, many object like list and dictionaries are not supporting mutithreaded (support working in parallel), so you can not use them to add members to the list during a report or a consolidation.
But there are multithreaded versions you can use for this purpose
'Additional Imports for concurent list and dictionary
Imports System.Collections.Concurrent
'create a concurrent dictionary
Dim concDict As New ConcurrentDictionary()
03-16-2022 08:37 AM
When a user runs a business rule which generates a global object, is this same object accessible to other users/sessions or only applicable to user who generated the global?
04-04-2022 01:31 PM
Only for this user and only for this activity. The next calculation or the next report creates its own global object. But it bridges different dataunits of a consolidation. Or different cells of a report. Very powerful.