How To Insert Varbinary Data In Ms Sql For Acumatica

 

Hello everybody,

sometime it is needed to insert some binary information in one or another table inside of Acumatica. Quite often developers just modify existing record in table UploadFile or UploadFileRevision.

But I don't like such approach, as it is prone to errors and potentially can harm some of your existing data. That's why I propose to use cast operator of MS SQL. Take a look at following example:

insert into UploadFileRevision(CompanyID, FileID, FileRevisionID, Data, Size, CreatedByID, CreatedDateTime, CompanyMask) values
								(2, '35b15ad7-b5c3-4a19-aa77-3a24c046d689', 1, 
													CAST('wahid' AS VARBINARY(MAX)),
													4, 
													'B5344897-037E-4D58-B5C3-1BDFD0F47BF9',
													'2016-06-08 08:53:50.937',
																	0xAA)

 

Take notice of 

CAST('wahid' AS VARBINARY(MAX)),

line. It will insert into local dev instance database varbinary representation of wahid. 

 

How To Imitate Click On Confirm Shipment In Acumatica

 

Hello everybody,

Today I want to describe how to imiate click on menu item "Confirm shipment" in Acumatica. 

Probably your first guess will be just call method ConfirmShiment of graph SOShipmentEntry. But for now Acumatica team has another advice in order to call this action. Instead of calling method ConfirmShipment you'll need to have a bit more steps.

Code sample below demonstrates those necessary steps:

SOShipmentEntry shipmentGraph = PXGraph.CreateInstance<SOShipmentEntry>(); //Create instance of Graph
PXAutomation.CompleteSimple(shipmentGraph.Document.View);
PXAdapter adapter2 = new PXAdapter(new DummyView(shipmentGraph, shipmentGraph.Document.View.BqlSelect,
						 new List<object> { shipmentGraph.Document.Current }));
adapter2.Menu = SOShipmentEntryActionsAttribute.Messages.ConfirmShipment;
adapter2.Arguments = new Dictionary<stringobject>
{
		{"actionID"SOShipmentEntryActionsAttribute.ConfirmShipment}
};
adapter2.Searches = new object[]{shipmentGraph.Document.Current.ShipmentNbr};
adapter2.SortColumns = new[] { "ShipmentNbr"};
soShipmentGraph.action.PressButton(adapter2);
TimeSpan timespan;
Exception ex;
while (PXLongOperation.GetStatus(shipmentGraph.UID, out timespanout ex) == PXLongRunStatus.InProcess)
{ }
//Here you'll have your shipment confirmed

And DummyView looks like this:

public class DummyView : PXView
    {
        List<object> _Records;
        internal DummyView(PXGraph graphBqlCommand commandList<objectrecords)  : base(graphtruecommand)
        {
            _Records = records;
        }
        public override List<objectSelect(object[] currentsobject[] parametersobject[] searchesstring[] sortcolumns
bool[] descendingsPXFilterRow[] filtersref int startRowint maximumRowsref int totalRows)         {             return _Records;         }     }

If you wonder, why calling ConfirmShipment is not enough, answer is this: ConfirmShipment cal will confirm shipment, but it will not execute Automation Steps. Thats why all of mentioned steps are needed. Otherwise, you'll make long research on question, why something doesn't work in the same way, as it works in UI, but doesn't work from my code.

 

Database Of Acumatica Is In Recovery Pending Condition

 

Hello everybody,

recently I've got interesting situation, when my database for Acumatica developed turned to be in Pending condtion. In order to deal with it, I've executed following SQL:

 

ALTER DATABASE YourDatabase SET EMERGENCY;
GO
ALTER DATABASE YourDatabase set single_user
GO
DBCC CHECKDB (YourDatabase, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO
ALTER DATABASE YourDatabase set multi_user
GO

 

and my database turned back to normal.

Update on 10/08/2019

declare @dbName nvarchar(50);
set @dbName = 'yourDatabase';
 
exec( 'ALTER DATABASE' +@dbName  + ' SET EMERGENCY;')
 
exec ('ALTER DATABASE ' + @dbName + '  set single_user')
 
exec ('DBCC CHECKDB (' + @dbName + ' , REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;')
 
exec ('ALTER DATABASE ' + @dbName +' set multi_user');

I've modified script to a bit another

 

Three States Of Fields In Acumatica

 

Hello everybody,

today I want to write a short note on three states of fields existing in Acumatica:

  1. Exists but is empty
  2. Exist and have value
  3. Has null

If to speak about string, it can exist like this:

  1.  
  2. Some value
  3.  

Do you see difference between 1 and 3? Not easy. As usually developers of C#, show this difference like this:

  1. ""
  2. "Some Value"
  3. null

And following screenshot with explanation shows how it works in case of SOAP contracts:

 so, while you make integration, keep that in mind

 

New Functions For Redirect In Acumatica

 

Hello everybody,

today I want to say few words about new functions for redirect in Acumatica, and particularly about class PXRedirectHelper. 

Classical approach from T200/T300 manual may look like this:

var currentCse = Cases.Current;
if(currentCse == null)
	return;
 
 
var graph = PXGraph.CreateInstance<CRCaseMaint>();
graph.Case.Current = graph.Case.Search<CRCase.caseCD>(currentCse.CaseCD);
if (graph.Case.Current != null)
{
	throw new PXRedirectRequiredException(graphtrue"Case details");
}

But with new function all of those lines can be simplified to this:

PXRedirectHelper.TryRedirect(Cases.Cache, Cases.Current, "Edit case"PXRedirectHelper.WindowMode.NewWindow);

With that approach you'll get the same result, but just in one line of code.

 

Simplest Cachinng Explanation

 

Hello everybody,

today I want to give one more explanation of how to use caching and slots for caching purposes. Also there are plenty of articles on the subject,  I want to give one more with simplest recipe. So, if you need to cache something, you'll need to follow this procedure:

  1. declare you class as something that inherits IPrefetchable
  2. Create some placeholder in your class for storing items in the cache
  3. Implement Prefetch
  4. Implement GetSlot

 

Take a look on the code below, how it can be done:

public class ArTranFetcher : IPrefetchable
{
	private List<ARTran> _arTranList = new List<ARTran>();
 
	public void Prefetch()
	{
		_configurableList = new List<ARTran>();
 
		var dbRecords = PXDatabase.Select<ARTran>();
		foreach (var csAttributeDetailConfigurable in dbRecords)
		{
			_arTranList.Add(csAttributeDetailConfigurable);
		}
	}
 
	public static List<ARTran> GetARTrans()
	{
		var def = GetSlot();
		return def._arTranList;
	}
		
	private static ArTranFetcher GetSlot()
	{
		return PXDatabase.GetSlot<ArTranFetcher>("ARtranFetcherSlot"typeof(ARTran));
	}
 
}

 

few more explanations on presented code.

  1. Placeholder will be _arTranList 
  2. GetSlot will be monitoring database ARTran ( because of typeof(ARTran) statement ). So each time ARTRan will be updated, GetSlot will be executed automatically via framework.
  3. In your code you can get cached valus via following line of code: var arTrans = ArTranFetcher.GetARTrans();

 

with usage of such tricks, you can optimize plenty of staff. The only warning would be don't cache ARTran, as it will swallow up all memory of your server.

 

 

 

Acumatica Page Missing Under Google Chrome Browser

 

Hello everybody,

This one is a hot topic, recently chrome team released some changes to the Chrome Browser, so that some PAGES could get missing.

You still see Menu, still see screen list but the page itself is gone, blank, empty.

How to fix?

Just change settings in the Chrome:

1. Type chrome://flags/ in the browser address bar and press Enter.

2. You should see the list of options:

3. In the search bar type Lazy Frame or just Lazy:

4. Under Enable lazy frame loading choose Disabled:

5. Press Relaunch Now at the right bottom corner:

 

 

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
 

 

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

No Comments

Add a Comment
 

 

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. 

No Comments

Add a Comment