Separate creating unique values for multiple objects simultaneously

Hi. I have a script that creates unique values when adding new object in UNSAccountB. This script is used in process that starts on the Insert event. Process takes UID processed object and send UID to script (process is generated for each single object)

 

In script there is section which creates a list of unique values (that exists in OIM table). And script generates new value (by adding 1 to maximum value from list)

'Create List of String with UniqueIDs from Person 
	Dim numsStr As New List(Of String)()
	Dim f As ISqlFormatter = Session.SqlFormatter()
	Dim colPerson As IEntityCollection
    Dim queryPerson = Query.From("Person").Where(String.Format("CCC_UniqueID LIKE 'P%'")).Select("CCC_UniqueID ")
	colPerson = Session.Source.GetCollection(queryPerson)
	For Each User As IEntity In colPerson
		numsStr.Add(User.GetValue("CCC_UniqueID ").ToString())
	Next
'Further is creating new list of integers from numsStr and find max value…

 

If multiple entries are added at the same time I have multiple processes and lists of existing unique values for different objects are the same – so script returns identical values for different objects, and I need the values to be unique.

 

How to split processing of process for multiple objects?