Is it possible to use old values in a script?

I would like to use $CustomProperty01[o]$ using Entities

Dim empQr = Query.From("Person").Where(String.Format("CentralAccount = '{0}'",cAcc)).SelectAll()
Dim empRes = Session.Source.GetCollection(Of Person)(empQr, EntityCollectionLoadType.Slim)

For Each emp As Person In empRes
     ' Value at the moment
     emp.CustomProperty01    
Next


  • Good question!

    #If Not SCRIPTDEBUGGER
    	Imports VI.DB.Compatibility
    #End If
    
    Public Function CCC_PreviousLastName(ByVal uidPerson As String) As String
    	
    	Dim person = Session.Source.Get("Person", uidPerson, EntityLoadType.ReadOnly)
    	Dim histPerson As New VI.DB.History.ColumnHistory(person.CreateSingleDbObject(connection), "LastName",  Connection.LocalNow.AddDays(-100).ToUniversalTime)
    	Dim previousLastName = histPerson.Changes.First.Changes _
       		.Where(Function(c) String.Equals(c.Columnname, "LastName", StringComparison.OrdinalIgnoreCase)) _
       		.Select(Function(c) DbVal.ConvertTo(Of String)(c.OldValue)).FirstOrDefault()
    
    	Return(previousLastName)
    End Function

    CreateSingleDbObject is not a member of IEntity (4376610)
    https://www.oneidentity.com/community/identity-manager/f/forum/20816/method-call-getoldvalue

    VI.DB.History.ColumnHistory() still works with ISingleDbObject not with the "new" entitytype
    Maybe there's better alternative that uses enitytype?

  • This would be my generic solution for an entity column's latest "old" value.

    Public Function CCC_PreviousColumnValue(ByVal xObjectKey As String, columnName As String, Optional backTo As Date = Nothing) As String
        If String.IsNullOrWhiteSpace(xObjectKey) Then
            Throw New ArgumentNullException(NameOf(xObjectKey))
        End If
        If String.IsNullOrWhiteSpace(columnName) Then
            Throw New ArgumentNullException(NameOf(xObjectKey))
        End If
    
        Dim source = Session.Resolve(Of History.IHistorySource)()
        Dim columns = New List(Of String) From {columnName}
    
        Dim previousColumnValue = source.GetChanges(New DbObjectKey(xObjectKey), columns, backTo, History.HistoryMode.WithFkDisplays).
            OrderByDescending(Function(x) x.ChangeTime).FirstOrDefault?.GetOldValue(columnName)
    
        Return previousColumnValue
    End Function