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.

How to deal with PX.Data.PXException: Cannot access the uploaded file. Failed to get the latest revision of the file error message

Hello everybody,

today I want describe how to deal with following Acumaitca error message: 

Publish Customization

Compiled projects: GAPRojectsBusinessAccounts,PayrollV2Acu2018Build20190328,EBizCharge2018R2,GACustomization
Validation started.
PX.Data.PXException: Cannot access the uploaded file. Failed to get the latest revision of the file a4353331-8f7f-4b3b-a881-2cdb4d5451e3
   at Customization.CstBinFile.GetFileFromDb() in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\CstDocumentDOM\CstBinFile.cs:line 120
   at Customization.CstBinFile.SaveFiles(FilesCollection context) in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\CstDocumentDOM\CstBinFile.cs:line 65
   at Customization.CstDocument.GetFiles(FilesCollection context) in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\CstDocumentDOM\CstDocument.cs:line 335
   at Customization.CstManager.ValidateDocument(CstDocument doc, Action`1 logMessageDelegate, Boolean patchLibInDB) in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\Global\CustomizationManager.cs:line 245
   at PX.Customization.CstValidationProcess.ValidateCurrentDocument(Action`1 logMessage) in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\Publish\CstValidationProcess.cs:line 399
   at PX.Customization.CstValidationProcess.CompileInternal() in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\Publish\CstValidationProcess.cs:line 223
   at PX.Customization.CstValidationProcess.<>c__DisplayClass6_0.<ProcessRequest>b__0() in C:\Bld\AC-FULL2018R226-JOB1\Sources\NetTools\PX.Web.Customization\Publish\CstValidationProcess.cs:line 133

 

The reason of this error can happen after you restore snapshot from some company in your instance. For example, recently I worked with one company, which had a lot of sesitive information in their Acumatica instance, and the only way of dealing with them was preparation by that company of some representative information and giving me snapshot. But after snapshot restoration, i had plenty of adventures, about which you can read below.

With help of resharper I have found that class CstBinFile has method GetFileFromDb, which looks like this:

public byte[] GetFileFromDb()
{
  if (this.IsBinContent)
    return this.BinContent;
  Guid id = this.FileID.Value;
  UploadFileRevision lastRevision = CstBinFile.GetLastRevision(id);
  if (lastRevision == null)
    throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA("Cannot access the uploaded file. Failed to get the latest revision of the file {0}", (objectid));
  return lastRevision.Data;
}

As you can see from C# code presented, it takes latest revision. Method GetLastRevision have this line:

 
return (UploadFileRevision) PXSelectBase<UploadFileRevision, PXSelectReadonly<UploadFileRevision, Where<UploadFileRevision.fileID, 

Based on this, I decided to do the following:

  1. In database located table UploadFile, and by random choince modified column FileId, and set it to a4353331-8f7f-4b3b-a881-2cdb4d5451e3.
  2. The same step did in table UploadFileRevision.

and tried to make publish one more time.

This step helped to remove issue with that exact file, but didn't help to resovle issue with other guids. I spend some time on creation of new guids, but after 10 guids I become tired, and created following SQL code to automate it's creation:

declare @UploadFileRevision table(
	[CompanyID] [int] NOT NULL,
	[FileID] [uniqueidentifier] NOT NULL,
	[FileRevisionID] [int] NOT NULL,
	[Data] [varbinary](max) NOT NULL,
	[Size] [int] NOT NULL,
	[CreatedByID] [uniqueidentifier] NOT NULL,
	[CreatedDateTime] [datetime] NOT NULL,
	[Comment] [nvarchar](500) NULL,
	[OriginalName] [nvarchar](255) NULL,
	[OriginalTimestamp] [datetime] NULL,
	[CompanyMask] [varbinary](32) NOT NULL,
	[BlobHandler] [uniqueidentifier] NULL,
	[RecordSourceID] [smallint] NULL)
 
declare @uploadFile TABLE (
	[CompanyID] [int] NOT NULL,
	[FileID] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[CreatedByID] [uniqueidentifier] NOT NULL,
	[CreatedDateTime] [datetime] NOT NULL,
	[Versioned] [bit] NOT NULL,
	[CheckedOutBy] [uniqueidentifier] NULL,
	[CheckedOutComment] [nvarchar](500) NULL,
	[LastRevisionID] [int] NOT NULL,
	[PrimaryPageID] [uniqueidentifier] NULL,
	[PrimaryScreenID] [varchar](8) NULL,
	[IsHidden] [bit] NULL,
	[Synchronizable] [bit] NULL,
	[SourceType] [char](1) NULL,
	[SourceUri] [nvarchar](255) NULL,
	[SourceLogin] [nvarchar](255) NULL,
	[SourcePassword] [nvarchar](1024) NULL,
	[SourceIsFolder] [bit] NULL,
	[SourceMask] [nvarchar](255) NULL,
	[SourceNamingFormat] [char](1) NULL,
	[SourceLastExportDate] [datetime] NULL,
	[SourceLastImportDate] [datetime] NULL,
	[IsPublic] [bit] NOT NULL,
	[NoteID] [uniqueidentifier] NULL,
	[CompanyMask] [varbinary](32) NOT NULL,
	[RecordSourceID] [smallint] NULL,
	[SshCertificateName] [nvarchar](50) NULL)
 
 insert into @UploadFileRevision select top 1 * from UploadFileRevision
 insert into @uploadFile([CompanyID]
           ,[FileID]
           ,[Name]
           ,[CreatedByID]
           ,[CreatedDateTime]
           ,[Versioned]
           ,[CheckedOutBy]
           ,[CheckedOutComment]
           ,[LastRevisionID]
           ,[PrimaryPageID]
           ,[PrimaryScreenID]
           ,[IsHidden]
           ,[Synchronizable]
           ,[SourceType]
           ,[SourceUri]
           ,[SourceLogin]
           ,[SourcePassword]
           ,[SourceIsFolder]
           ,[SourceMask]
           ,[SourceNamingFormat]
           ,[SourceLastExportDate]
           ,[SourceLastImportDate]
           ,[IsPublic]
           ,[NoteID]
           ,[CompanyMask]
           ,[RecordSourceID]
           ,[SshCertificateName])    select top 1 	   [CompanyID],
           [FileID]
           ,[Name]
           ,[CreatedByID]
           ,[CreatedDateTime]
           ,[Versioned]
           ,[CheckedOutBy]
           ,[CheckedOutComment]
           ,[LastRevisionID]
           ,[PrimaryPageID]
           ,[PrimaryScreenID]
           ,[IsHidden]
           ,[Synchronizable]
           ,[SourceType]
           ,[SourceUri]
           ,[SourceLogin]
           ,[SourcePassword]
           ,[SourceIsFolder]
           ,[SourceMask]
           ,[SourceNamingFormat]
           ,[SourceLastExportDate]
           ,[SourceLastImportDate]
           ,[IsPublic]
           ,[NoteID]
           ,[CompanyMask]
           ,[RecordSourceID]
           ,[SshCertificateName]
		    from uploadFile
 
 -- 0cc8363d-dff7-4bc1-92df-62ad7f37ace0
 declare @fid uniqueidentifier
 set @fid = '0cc8363d-dff7-4bc1-92df-62ad7f37ace0'
 
 update @UploadFileRevision set FileID =@fid
 update @uploadFile set FileID =@fid
 
 insert into UploadFile ([CompanyID]
           ,[FileID]
           ,[Name]
           ,[CreatedByID]
           ,[CreatedDateTime]
           ,[Versioned]
           ,[CheckedOutBy]
           ,[CheckedOutComment]
           ,[LastRevisionID]
           ,[PrimaryPageID]
           ,[PrimaryScreenID]
           ,[IsHidden]
           ,[Synchronizable]
           ,[SourceType]
           ,[SourceUri]
           ,[SourceLogin]
           ,[SourcePassword]
           ,[SourceIsFolder]
           ,[SourceMask]
           ,[SourceNamingFormat]
           ,[SourceLastExportDate]
           ,[SourceLastImportDate]
           ,[IsPublic]
           ,[NoteID]
           ,[CompanyMask]
           ,[RecordSourceID]
           ,[SshCertificateName]) select [CompanyID]
           ,[FileID]
           ,[Name]
           ,[CreatedByID]
           ,[CreatedDateTime]
           ,[Versioned]
           ,[CheckedOutBy]
           ,[CheckedOutComment]
           ,[LastRevisionID]
           ,[PrimaryPageID]
           ,[PrimaryScreenID]
           ,[IsHidden]
           ,[Synchronizable]
           ,[SourceType]
           ,[SourceUri]
           ,[SourceLogin]
           ,[SourcePassword]
           ,[SourceIsFolder]
           ,[SourceMask]
           ,[SourceNamingFormat]
           ,[SourceLastExportDate]
           ,[SourceLastImportDate]
           ,[IsPublic]
           ,[NoteID]
           ,[CompanyMask]
           ,[RecordSourceID]
           ,[SshCertificateName] from @uploadFile
 insert into UploadFileRevision select * from @UploadFileRevision
 

And executed that script multiple times, but after 20-th execution I gave up, and decided to continue research. In order to find, where is the problem, I've decided to find which table in database is exact source, from which Acumatica reads records. For such purposes I always use stored procedure from this article

As a result, I have found, that Acumatica has table CustObject, in which there are plenty of objects, created by Acumatica. 

In order to make my life simpler, I've decided to clean table CustObject, but of course with previous creation of backup. 

delete  from CustObject

After that I've decided to publish cutomizations one more time, and was successful!

Summary

If you ever see error message Cannot access uploaded file ..... I'd recommend you just to delete data from table CustObject as fastest solution

 

Strong name validation by pass

Hello,

here I want to leave a short notice how to manage strong name validation in Windows. For this purpose you can manage via following keys in regedit:

To enable the strong-name bypass feature for all applications: switch the value for AllowStrongNameBypass to 1 in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework keys

With those changes you'll get your validation turn off. If you want to set it on, then set AllowStrongNameBypass to 0

DashboardPageTitleModule does not implement interface member PX.Web.UI.ITitleModule.GetDefaultVisibility in Acumatica

Hello everybody,

today I want to describe how to live with following error message:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0535: 'DashboardPageTitleModule' does not implement interface member 'PX.Web.UI.ITitleModule.GetDefaultVisibility()'

Source Error:

 
Line 2:  using PX.Web.UI;
Line 3:  
Line 4:  public class DashboardPageTitleModule : ITitleModule
Line 5:  {
Line 6:  	public void Initialize(ITitleModuleController controller)


Source File: c:\Program Files\Acumatica ERP\GehmanAccountingDev\App_Code\Auxiliary\DashboardPageTitleModule.cs    Line: 4 


 




Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3815.0

 

Some time it appears on some Acumatica versions. Steps for dealing with it are the following:

  1. Copy with replace all files from Acumatica folder [Acumatica installation folder]\Files\Bin, everything.
  2. Remove reference for your project in Visual studio
  3. In Post-build event command line: of Visual studion type something like this:

xcopy /s "c:\Sources\Kensium\KN.GehmanAccounting\bin\Debug\KN.manAccounting.dll" "c:\Program Files\Acumatica ERP\manAccountingDev\Bin\" /F /Y
xcopy /s "c:\Sources\Kensium\KN.GehmanAccounting\bin\Debug\KN.manAccounting.pdb" "c:\Program Files\Acumatica ERP\manAccountingDev\Bin\" /F /Y

On screenshot level it loos like this: 

With such maneure you'll get working workaround of replacing files in your built. 

Merge few customizations into one

Hello everybody,

today I want to leave a short notice on how to join few customizations into one. Basically all you need is publish customizations you want to have merged, and then on Customization Projects form ( SM204500 ) click on button View Published and then click on Download package. In that way you'll get Customization.zip which will be merged result of published customizations.

How to modify PXIntList dynamically in Acumatica

Hello everybody,

today I want to leave a short code sample on how to modify PXIntList or dropdown list in Acumatica. Below goes code sample of it:

protected virtual void _(Events.RowSelected<CROpportunity> e)
{
    if (e.Row == null)
        return;
    var opportunityExtension = e.Row.GetExtension<CROpportunityExt>();
 
    if (opportunityExtension.UsrProduct == 0)
    {
        var listInts = new List<int>();
        var listStrings = new List<String>();
 
        listInts.Add(0);
        listInts.Add(1);
        listInts.Add(2);
 
        listStrings.Add("String 1");
        listStrings.Add("String 2");
        listStrings.Add("String 3");
 
        PXIntListAttribute.SetList<CROpportunityExt.usrProposition>(e.Cache, e.Row, listInts.ToArray(), listStrings.ToArray());
    }
 
    if (opportunityExtension.UsrProduct == 1)
    {
        var listInts = new List<int>();
        var listStrings = new List<String>();
 
        listInts.Add(0);
        listInts.Add(3);
        listInts.Add(5);
 
        listStrings.Add("String 2");
        listStrings.Add("String 3");
        listStrings.Add("String 4");
 
        PXIntListAttribute.SetList<CROpportunityExt.usrProposition>(e.Cache, e.Row, listInts.ToArray(), listStrings.ToArray());
    }
}

This code sample has two most important parts: 

  1. RowSelected ( declared over new syntax )
  2. PXIntListAttribute.SetList<CROpportunityExt.usrProposition> call

With usage of those two principles you can easily get modifiable collection accoding to necessary conditions in your code.

Creating the new Company, set settings for it from snapshot

Hello everybody,
today I want share with you, how you can create new Company and set it settings.

For creating new company, we should go to "Tenants" screen:

Notice, that in old vercions of acumatica instead the "Tenants" was the "Companies":

Let create new company, and give it name "Exotic Places":

When process of creation is finished, we'll automatically be logged out: