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
}
}