Has anyone created a script using the API that would create an action on save. For example, if a constuients record firstname is changed, take the old value and write it to an action on the consituent record.
Anyone attempted this?
Mark
Absolutely. This is a straight forward task. Using the VBA module you would capture the values before the record is opened and then on saving the record you would compare the values to those when the record was opened and record any change. This is common where you want to keep an audit trail of changes made.
Please don't hesistate to contact me if you would like any more information.
David
You would need the VBA module [edit: as David mentioned] rather than an API license to do this. This code shows one way to track what values were changed TO, but you could extend it further to also track/log initial values. I don't know that actions are good place to store audit trail though, as a user could change the action records (and you'll have a LOT of action records). I would recomend a separate database table.
Public Sub Constituent_BeforeSave(oRecord As Object, bCancel As Boolean) Dim oM As IBBMetaField, oD As IBBDataObject Set oD = oRecord Set oM = oRecord
Dim sChaChaChaChanges As String Dim i As Long For i = 1 To oM.Count If oD.FieldIsDirty(i) Then sChaChaChaChanges = sChaChaChaChanges & oM.DisplayText(i) & " changed to '" & oD.Fields(i) & "'" & vbCrLf End If Next i
Dim oConstit As CRecord If Len(sChaChaChaChanges) Then Dim oA As CAction, oA2 As IBBAction2 Set oA = New CAction oA.Init REApplication.SessionContext oA.Fields(ACTION_fld_RECORDS_ID) = oD.Fields(RECORDS_fld_ID) oA.Fields(ACTION_fld_CATEGORY) = "Task/Other" Set oA2 = oA With oA2.Notepads.Add .Fields(NOTEPAD_fld_NotepadDate) = FormatDateTime(Now, vbShortDate) .Fields(NOTEPAD_fld_NotepadType) = "Audit Trail" '<-- use a valid type .Fields(NOTEPAD_fld_Description) = "changes at " & Now .Fields(NOTEPAD_fld_Notes) = sChaChaChaChanges End With oA.Save oA.Closedown Set oA = Nothing Set oA2 = Nothing End If Set oD = Nothing
End Sub