Welcome to Forums Sign in | Join | Help | Forums
in Search





Make the world a better place.

Creating an Action on Save

Last post 05-08-2008 10:05 PM by Jeff Montgomery. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-07-2008 9:41 AM

    • Mark Banbury
    • Not Ranked
    • Posts 1
    • Organization: Plan International Canada Inc

    Creating an Action on Save

    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

    Vice President & CIO
    Vice-président et DPI
    Plan Canada

    mbanbury@plancanada.ca

     

    Filed under:
  • 05-07-2008 12:09 PM In reply to

    • David Zeidman
    • Top 25 Contributor
    • Posts 164
    • Organization: Zeidman Development
    • Products:  The Raiser's Edge

    Re: Creating an Action on Save

    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

    David Zeidman
    Zeidman Development
    http://www.zeidman.info

    Check out my RE API blog
    http://www.re-decoded.com
    Filed under: ,
  • 05-08-2008 10:05 PM In reply to

    Re: Creating an Action on Save

    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

    Filed under:
Page 1 of 1 (3 items)