Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hi,

                                    I am planning to include Audit Trial in my project but the concern i have is the i dont want to create the collection property for Audit Log in every BO i have. Instead, i was thinking to have a ViewController (of DetailView) type and add a popupaction button to it to invoke the log for any BO. 

                                    Could you please guide me on that.

                                    So far I have created the following but not sure how to pop this up.

                                    [VB.NET]
                                    Private Sub ViewAudit_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles ViewAudit.Execute Dim os As IObjectSpace = Application.CreateObjectSpace() Dim master As Object = os.GetObject(View.CurrentObject) Dim sess = DirectCast(Me.ObjectSpace, XPObjectSpace).Session Dim _auditTrail As XPCollection(Of AuditDataItemPersistent) _auditTrail = AuditedObjectWeakReference.GetAuditTrail(sess, master) 'Dim dv As DetailView = Application.CreateDetailView(os, _auditTrail) 'dv.ViewEditMode = ViewEditMode.View 'e.ShowViewParameters.CreatedView = dv End Sub

                                1 Solution

                                Creation Date Rating Importance Sort by
                                1

                                Hello,

                                There are several good ways to approach this, and in both of them, you will need to create a ListView for the  AuditDataItemPersistent type and then apply the required filter to the ListView.CollectionSource.Criteria property as described at Concepts > Filtering > Criteria Property of a List View's Collection Source:
                                1. Compose a filter based on your XPCollection using the DevExpress.Data.Filtering > InOperator feature (see the Q480741 ticket for an example).
                                2. Compose a filter manually as shown below:

                                [C#]
                                using System; using DevExpress.Data.Filtering; using DevExpress.ExpressApp.Xpo; using DevExpress.Xpo; namespace MainDemo.Module.Controllers { public partial class PopupNotesController : ViewController { private void ShowNotesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs args) { ListView lv = Application.CreateListView(Application.CreateObjectSpace(typeof(AuditDataItemPersistent)), typeof(AuditDataItemPersistent), true); GroupOperator criteria = new GroupOperator(GroupOperatorType.And); criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetType", ((XPObjectSpace)ObjectSpace).Session.GetObjectType(View.CurrentObject))); criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(View.CurrentObject)))); lv.CollectionSource.Criteria["ByTargetObject"] = criteria; args.View = lv; }
                                [VB.NET]
                                Imports System Imports DevExpress.Data.Filtering Imports DevExpress.ExpressApp.Xpo Imports DevExpress.Xpo Namespace MainDemo.Module.Controllers Partial Public Class PopupNotesController Inherits ViewController Private Sub ShowNotesAction_CustomizePopupWindowParams(ByVal sender As Object, ByVal args As CustomizePopupWindowParamsEventArgs) Dim view As ListView = Application.CreateListView(Application.CreateObjectSpace(GetType(AuditDataItemPersistent)), GetType(AuditDataItemPersistent), True) Dim criteria As New GroupOperator(GroupOperatorType.And) criteria.Operands.Add(New BinaryOperator("AuditedObject.TargetType", CType(ObjectSpace, XPObjectSpace).Session.GetObjectType(View.CurrentObject))) criteria.Operands.Add(New BinaryOperator("AuditedObject.TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(View.CurrentObject)))) view.CollectionSource.Criteria("ByTargetObject") = criteria args.View = view End Sub







                                See Also:
                                Concepts > Extra Modules > Audit Trail Module Overview > Customize the Audit Trail System
                                Audit - How to show audit entries for a current object and for each object from its collection property in one list
                                How to display audit info for deleted objects

                                Show all comments
                                • MohammedFarooq 05.25.2017
                                  Thanks for your efforts in putting this solution Dennis.

                                  But the code is not running as View.CurrentObject is returning null for me all the time at the below line.

                                  criteria.Operands.Add(New BinaryOperator("AuditedObject.TargetType", CType(ObjectSpace, XPObjectSpace).Session.GetObjectType(View.CurrentObject)))
                                • This code worked fine in my tests for the scenario and code I demonstrated in my previous message.
                                  If this does not work for you, attach your own sample project and screenshots showing your different use-case scenario and execution context so that I can assist you further. For now, I can only have these guesses:
                                   - you are evaluating View.CurrentObject in an incorrect place, e.g. Controller's constructor;
                                   - the target Controller is not for the DetailView, but for a ListView;
                                   - the current DetailView object is really not initialized;
                                  See Also: Task-Based Help > How to: Access Objects Selected in the Current View

                                • Christian Wolff 05.26.2017
                                  Hi,

                                  is it possible that you use the eXpand Framework? Then the return is null from Dennis Code because you have to change the BaseObject for AuditTrail to XpandAuditDataItemPersistent



                                  ListView view = Application.CreateListView(Application.CreateObjectSpace(typeof(XpandAuditDataItemPersistent)), typeof(XpandAuditDataItemPersistent), true);

                                  GroupOperator criteria = new GroupOperator(GroupOperatorType.And);
                                  criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetType",((XPObjectSpace)ObjectSpace).Session.GetObjectType(View.CurrentObject)));
                                  criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(View.CurrentObject))));
                                  view.CollectionSource.Criteria["ByTargetObject"] = criteria;
                                  e.View = view;
                                • MohammedFarooq 05.26.2017
                                  Hi Dennis & Christian,

                                  1. The code is in Viewcontoller of DetailView type.
                                  2. I am not using Xpand Framework.
                                  3. The code is being called from PopupParametersAction button of a detailview.


                                • Thanks for your update, Mohammed. The information you provided at this stage does not allow me to research this case further... Please take another moment to review the essential information I requested in my previous message and provide it. If you cannot do this, attach a modified version of the MainDemo app where the modified PopupNotesController class does not work for you. I want to help you and look forward to hearing from you.

                                • MohammedFarooq 05.26.2017
                                  Hi Dennis,

                                  Please find the attaches sample project in which the error is reproduced, i have included a video as well.
                                • MohammedFarooq 05.27.2017
                                  Hi Dennis,

                                  I got confused with the View.CurrentObject in your code but now figured out the issue. The updated code is below which is working fine now.

                                  [VB.NET]
                                  Dim obj As Object = view.CurrentObject Dim view1 As ListView = Application.CreateListView(Application.CreateObjectSpace(GetType(AuditDataItemPersistent)), GetType(AuditDataItemPersistent), True) Dim criteria As New GroupOperator(GroupOperatorType.And) criteria.Operands.Add(New BinaryOperator("AuditedObject.TargetType", CType(ObjectSpace, XPObjectSpace).Session.GetObjectType(obj))) criteria.Operands.Add(New BinaryOperator("AuditedObject.TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(obj)))) view1.CollectionSource.Criteria("ByTargetObject") = criteria e.View = view1



                                • I am happy to hear of your progress, Mohammed. I have also updated the original code (I used the automatic C# to VB converter for this) so that VB.NET did not confuse "View" and "view" objects.

                                • Randy Jean 06.28.2017
                                  This is a great solution!

                                  We don't audit all our objects so I added a little code in the OnActivated event of this controller to dynamically hide this action if the object is not audited OR the user is not Administrator:

                                  [C#]
                                  popupWindowShowAuditHistoryAction.Active["HideShowAuditHistoryAction"] = (AuditTrailService.Instance.Settings.IsTypeToAudit(View.CurrentObject.GetType()) && ((User)SecuritySystem.CurrentUser).IsAdministrator()) ;

                                  IsAdministrator is a custom method on my user class:

                                  [C#]
                                  [Browsable(false)] public bool IsAdministrator() { bool ladmin = false; foreach (PermissionPolicyRole role in Roles) { if (role.IsAdministrative) { ladmin = true; } } return ladmin; }

                                • Thanks for sharing, Randy!

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners