Loading ...

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

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5