Use Acumatica xRP Platform from Console App

Hi All,

User-Interface-Console-icon

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!

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

  1. 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();
    graph.BatchModule.Insert();

    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.

  2. 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 *