Use Acumatica xRP Platform from Console App

Hi All,


Did you know that it is not necessary to have a Web Site under IIS to get benefits from Acumatica Platform?

You actually can run Acumatica platform even from console app!

To do this you just simple do following:

  1. Create Console Application in Visual Studio
  2. Add references to (PX.Common.dll, PX.Data.dll, PX.Objects.dll)
  3. Copy web.config from Acumatica site to app.config of your console application
  4. Specify user and company using PXLoginScope
  5. Use Acumatica Platform as normally you do that.

Here you can find a code example followed by some comments:

namespace AcumaticaConsole
	class Program
		static void Main(string[] args)
			using (new PXLoginScope("admin@Demo"))
				PXGraph graph = PXGraph.CreateInstance<PXGraph>();

				foreach (Account row in PXSelect<Account>.Select(graph))
					Console.WriteLine(row.AccountCD + " - " + row.Description);

App.config file is required to Acumatica platform to get proper environment configurations, database connection and other settings. For experiments you can just take whole file and replace it, so you don’t need to make a manual merge. If you use your own configurations in App.config, than you need to merge your configurations with Acumatica
configurations. Please try to avoid to use same names or settings as Acumatica uses as it may affect Acumatica execution.

Acumatica App Config

PXLoginScope is required to identify user and company that should be used for database selects. PXLoginScope is scope type class and will be effective only for nested code, so as soon as you leave the scope block user is logged out.
Please also note that login is filled with the following format “username@company”. Acumatica will automatically parse it and extract user and company for internal login.
Password is not required here as the login done from code. Alternatively you can login user using PXLogin class, where password will be checked.

Now you can use your Favorite BQL even from Console App 🙂 Or write a fast testing program without screen or interface!

Acumatica Console App

Hope it helps and have fun!

6 Replies to “Use Acumatica xRP Platform from Console App”

  1. Sergey, Thanx for all your contributions to the community. I ran this hack when it first came out and it worked fine but now it throws errors:

    Message=Error: Segmented Key ‘ACCOUNT’ cannot be found in the system.
    at PX.Data.PXCacheCollection.get_Item(Type key)
    at PX.Data.PXView..ctor(PXGraph graph, Boolean isReadOnly, BqlCommand select)
    at PX.Data.PXTypedViewCollection.InitializeView(BqlCommand command, Boolean readOnly)
    at PX.Data.PXTypedViewCollection.GetView(BqlCommand command, Boolean readOnly)
    at PX.Data.PXSelectBase`1.selectBound[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] currents, Object[] pars)
    at PX.Data.PXSelectBase`[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
    at PX.Data.PXSelectBase`2.SelectWindowed[Resultset](PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
    at PX.Data.PXSelectBase`2.Select[Resultset](PXGraph graph, Object[] pars)
    at PX.Data.PXSelectBase`2.Select(PXGraph graph, Object[] pars)
    at AcmaConsole.Program.Main(String[] args) in C:\Users\rcm.RCM-LAP\source\repos\AcmaConsole\Program.cs:line 14
    Any help is appreciated,,,,

    1. Rob,
      I think you have incorrectly used PXDimensionAttrute or maybe an incorrect configuration in the database.
      In any case, I recommend you create a support case so our dev team can review your code.

  2. I am trying to create a journal entry in Tenant B while I am logged into Tenant A.

    I am able to change the login scope using the PXLoginScope. I’ve tested that I am able to select data from Tenant B.

    However, if I create a JournalEntry graph after changing the login scope to Tenant B, it is still defaulting some parts of the GLTran as being Tenant A. It is strange because some defaults such as the default subID are correct but I cannot get the BranchID or LedgerID of the GLTran to reflect Tenant B. This causes the GLTran_BranchLedgerVerifying to throw an exception. The BranchID being passed to the method is correct because I have set it that way on the row but the underlying value in GLTran is still pointing to Tenant A.

    Is it even possible to “fake” the GLTran object to be in Tenant B?

    using (new PXLoginScope(“admin@LSCA”))

    JournalEntry graph = CreateInstance();

    GLTran row = graph.GLTranModuleBatNbr.Cache.CreateInstance() as GLTran;
    row = graph.GLTranModuleBatNbr.Insert(row);

    1. After further digging, I can change the BranchID and LedgerID of the GLTran but when the transaction goes through validation, even when I am processing the Save within the current login scopy, all the validation is done in the current Tenant.

      I have abandoned this effort.

      1. Joe, my recommendation is to use web services API to create a GI in the separate tenant. It will be much easier and you avoid all these issues.

  3. Awesome, these posts that open up possibilities of automation of managing my small collection of instances are my favorite.

    Thanks Sergey, this blog is overflowing with really amazing information

Leave a Reply

Your email address will not be published. Required fields are marked *