Workaround to manage "Notes" & "Files" Actions

  • 7 March 2023
  • 3 replies
  • 344 views

Userlevel 7
Badge +8

Hello Community,

I decided to post the below as I saw quite a few questions about managing the “Notes” & “Files” action buttons on the forms and how to prevent changes based on some conditions but couldn’t really see a solution or workaround that can benefit others. The below workaround is not so great but does the work. 

 

Notes: In the below example, I am reverting the changes made to the “Notes” of the Sales Orders which are not On Hold, Pending Approval, or Pending Processing. Disabling the “Notes” most of the time is not really work because people need to read the comments but at the same time, you do not want to change. I didn’t spend lots of time on it but couldn’t find an easy way to disable cache modification or the OK button of the Note dialog so instead, I am reverting the changes made on SOs which are not in the above-mentioned statuses. Users can make changes but it won’t be saved and when the page is “Refreshed” or closed or navigated to another document the original note will be displayed anyways. Not great but OK.

 

Files: As for the files, apparently Acumatica initializes the “WikiFileMaintenance” graph. For the same SO statuses, I am making the action buttons invisible so the user won’t be able to alter the existing attachments. The good news is you can develop the customization for all screens “Files” action button monitoring in this graph.

 

I just am performing simple validations and disabling the “Files” associated actions or reverting the changes made to the “Notes”. But, based on your use case you can develop more complicated conditions. For example, you may want to check if a user is a part of the “Admin” group and then avoid this restriction.

 

Any suggestion to improve and enhance this code is welcome.

 

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.SM;
using PX.Objects.SO;

namespace HCL
{
// Ignore changes made to the "Notes" and revert to the original
public class HCLSOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public static bool IsActive() => true;

//**************************************** Persist ****************************************//
#region Persist
public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
if (Base.Document.Current != null)
{
var status = Base.Document.Current.Status;

if (status != SOOrderStatus.Hold && status != SOOrderStatus.PendingApproval && status != SOOrderStatus.PendingProcessing)
{
Base.Caches[typeof(Note)].Clear();
}
}

baseMethod?.Invoke();
}
#endregion
}

// Prevent changing the existing "Files"
public class HCLSMWikiFileMaintenanceExt : PXGraphExtension<WikiFileMaintenance>
{
public static bool IsActive() => true;

//**************************************** Event Handlers ****************************************//
#region UploadFileWithIDSelector RowSelected
protected void _(Events.RowSelected<UploadFileWithIDSelector> e)
{
var isVisible = true;

if (e.Row != null)
{
// Sales Order
SOOrder salesOrder = SelectFrom<SOOrder>
.InnerJoin<NoteDoc>.On<SOOrder.noteID.IsEqual<NoteDoc.noteID>>
.Where<NoteDoc.fileID.IsEqual<@P.AsGuid>>
.View.ReadOnly.SelectWindowed(e.Cache.Graph, 0, 1, e.Row.FileID);

if (salesOrder != null)
{
var status = salesOrder.Status;
if (status != SOOrderStatus.Hold && status != SOOrderStatus.PendingApproval && status != SOOrderStatus.PendingProcessing)
{
isVisible = false;
}
}

// Develop Other Objects Logics & Set the Visibility Status
}

Base.Actions["save"].SetVisible(isVisible);
Base.Actions["delete"].SetVisible(isVisible);
Base.Actions["cancel"].SetVisible(isVisible);
Base.Actions["checkOut"].SetVisible(isVisible);
Base.Actions["undoCheckOut"].SetVisible(isVisible);
Base.Actions["uploadFile"].SetVisible(isVisible);
Base.Actions["uploadNewVersion"].SetVisible(isVisible);
}
#endregion
}
}

 


3 replies

Userlevel 7
Badge

Thank you for sharing this with the community @aaghaei !

Userlevel 3
Badge

Hi @aaghaei . I try Ignore changes made to the "Notes" and revert to the original for SoShipment screen.

namespace PX.Objects.SO {     public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>     {         public static bool IsActive() => true;         //**************************************** Persist ****************************************//         #region Persist         public delegate void PersistDelegate();         [PXOverride]         public void Persist(PersistDelegate baseMethod)         {             if (Base.Document.Current != null)             {                 var status = Base.Document.Current.Status;

                if (status != SOOrderStatus.Hold && status != SOOrderStatus.PendingApproval && status != SOOrderStatus.PendingProcessing)                 {                     Base.Caches[typeof(Note)].Clear();                 }             }

            baseMethod?.Invoke();         }         #endregion

}

}

I add break point at line 56, but it not active break point, in the screen, i until change notes as usual. Can you help me?

Userlevel 7
Badge +8

I didn’t see any break points but if you add BP but is not hit in VS I can say either your project is not bound to your instance or you are not complied the latest changes. Also try to close your browser and VS and rerun. I can not think of other common causes 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved