How to modify activities behavior on Business Accounts page

Hello everybody,

today I want to write a few words on how to modify behavior of buttons Add task, Add event, Add email, Add activity, ..., Add work item of Business Accounts page, one of which is shown on screenshot below:

The main issue of chaning it is in the fact, that it is not just ordinary buttons, but separate class, which has injection of logic. Part of it's declaration goes below:

public class CRActivityList<TPrimaryView> : CRActivityListBase<TPrimaryView, CRPMTimeActivity>
  where TPrimaryView : class, IBqlTable, new()
{
  public CRActivityList(PXGraph graph)
    : base(graph)
  {
  }
 
  public CRActivityList(PXGraph graphDelegate handler)
    : base(graphhandler)
  {
  }
}

To my surprise, in order to override it's behavior you'll need to inherit from CRActivityList, and add your logic, for example like this:

public class BusinessAccountMaintExt : PXGraphExtension<BusinessAccountMaint>
{
	[PXViewName(Messages.Activities)]
	[PXFilterable]
	[CRReference(typeof(BAccount.bAccountID), Persistent = true)]
	public CRActivityListModified<BAccount> Activities;
}
 
public class CRActivityListModified<TPrimaryView> : CRActivityList<TPrimaryView>
	where TPrimaryView : classIBqlTablenew()
{
	public CRActivityListModified(PXGraph graph)
		: base(graph)
	{
	}
 
	public CRActivityListModified(PXGraph graphDelegate handler)
		: base(graphhandler)
	{
	}
 
	public override IEnumerable NewTask(PXAdapter adapter)
	{
		try
		{
			base.NewTask(adapter);  // throws exception, catch it and add you needed logic
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CRTaskMaint)ex.Graph;
			var a = g.Tasks.Current;
			a.Subject = "Test Subject";
			a = g.Tasks.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewEvent(PXAdapter adapter)
	{
		try
		{
			base.NewEvent(adapter);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (EPEventMaint)ex.Graph;
			var a = g.Events.Current;
			a.Subject = "Test Subject";
			a = g.Events.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewMailActivity(PXAdapter adapter)
	{
		try
		{
			base.NewMailActivity(adapter);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CREmailActivityMaint)ex.Graph;
			var a = g.Message.Current;
			a.Subject = "Test Subject";
			a = g.Message.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewActivity(PXAdapter adapter)
	{
		return base.NewActivity(adapter);
	}
 
	protected override IEnumerable NewActivityByType(PXAdapter adapterstring type)
	{
		try
		{
			base.NewActivityByType(adaptertype);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CRActivityMaint)ex.Graph;
			var a = g.Activities.Current;
			a.Subject = "Test Subject";
			a = g.Activities.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
}

Few comments to presented code.

  1. All pop ups appear after exception, so you'll not be able to avoid exceptions, no matter what
  2. Your addendums should be modified in catch
  3. throw; will re-throw exception one more time. This is particularly interesitng detail, which you can re-use in some other scenarios when you need to deal with pop ups

Summary

Acumatica is very flexible, and the base flexibility mechanism is inheritance and polymorphism, two pillars of OOP.  In case if you need to change behavior of Cases screen, you'll need to inherit-override CRPMTimeActivity class.

No Comments

Add a Comment