Skip to main content
Question

Error when creating IN Transfer programmatically.

  • November 27, 2024
  • 6 replies
  • 149 views

I am trying to create a Transfer but keep getting error”:

GL Error: The financial period cannot be specified because the branch has not been specified in the Branch box.'
However I am setting the branch. Below is a screenshot of my code. 

 

                INTransferEntry transferEntry = PXGraph.CreateInstance<INTransferEntry>();

INSite fromWarehouse = SelectFrom<INSite>.Where<INSite.siteCD.IsEqual<@P.AsString>>.View.Select(transferEntry, "MAIN");
INSite toWarehouse = SelectFrom<INSite>.Where<INSite.siteCD.IsEqual<@P.AsString>>.View.Select(transferEntry, "PROJECT");

DateTime? docDate = DateTime.Now.ToUniversalTime();
int? orgID = PXAccess.GetParentOrganizationID(1);
FinPeriod fPeriod = finPeriodRepository.GetFinPeriodByDate(docDate, orgID);


INRegister transferRegister = (INRegister)transferEntry.transfer.Cache.Insert();

INRegister transferRegister = new INRegister();
DateTime? docDate = DateTime.Now.ToUniversalTime();
int? orgID = PXAccess.GetParentOrganizationID(1);
FinPeriod fPeriod = finPeriodRepository.GetFinPeriodByDate(docDate, orgID);
transferRegister.DocType = INDocType.Transfer;
transferRegister.TranDate = docDate;
transferRegister.FinPeriodID = fPeriod.FinPeriodID;
transferRegister.TranDesc = "Entered programmatically";
transferRegister.SiteID = fromWarehouse.SiteID;
transferRegister.ToSiteID = toWarehouse.SiteID;
transferRegister.TransferType = INTransferType.OneStep;
transferRegister.Hold = false;
transferRegister.BranchID = 1;
transferEntry.transfer.Current = transferEntry.transfer.Insert(transferRegister);
transferRegister = transferEntry.transfer.Current;
transferRegister = transferEntry.transfer.Update(transferRegister);
transferEntry.Actions.PressSave();

 

I can use the exact same detail when doing this from UI and there’s no issue saving it. 

From the UI, the Branch is readonly and only gets set when choosing the Warehouse ID. 

Trying it a different way and getting the same error and this right after setting the branch. 

 

 

                INTransferEntry transferEntry = PXGraph.CreateInstance<INTransferEntry>();

INSite fromWarehouse = SelectFrom<INSite>.Where<INSite.siteCD.IsEqual<@P.AsString>>.View.Select(transferEntry, "MAIN");
INSite toWarehouse = SelectFrom<INSite>.Where<INSite.siteCD.IsEqual<@P.AsString>>.View.Select(transferEntry, "PROJECT");

DateTime? docDate = DateTime.Now.ToUniversalTime();
int? orgID = PXAccess.GetParentOrganizationID(1);
FinPeriod fPeriod = finPeriodRepository.GetFinPeriodByDate(docDate, orgID);


INRegister transferRegister = (INRegister)transferEntry.transfer.Cache.Insert();

transferEntry.transfer.SetValueExt<INRegister.siteID>(transferRegister, fromWarehouse.SiteID);
transferEntry.transfer.SetValueExt<INRegister.toSiteID>(transferRegister, toWarehouse.SiteID);
transferEntry.transfer.SetValueExt<INRegister.branchID>(transferRegister, 1);
transferEntry.transfer.SetValueExt<INRegister.finPeriodID>(transferRegister, fPeriod.FinPeriodID);
transferRegister = transferEntry.transfer.Update(transferRegister);
transferEntry.Actions.PressSave();

 

 

 

What am I doing wrong here?

 

 

 

 

6 replies

  • Freshman I
  • January 21, 2026

Did you manage to resolve this issue? I am encountering exactly the same issue when trying to create a transfer programmatically from within a webhook. 


npetrosov31
Jr Varsity I
Forum|alt.badge.img+1
  • Jr Varsity I
  • January 21, 2026

hi ​@mauritzv,

Are you sure on the branchID= 1? can you watch if the branch id gets a value after that and is not empty before putting the finperiod?


Forum|alt.badge.img
  • Freshman II
  • January 21, 2026

This error typically occurs because FinPeriodID is being set and validated before the Branch is fully initialized on the document. Even though BranchID is assigned in code, the Insert() call triggers defaulting/validation logic immediately, and if the financial period is populated before the branch context is applied, Acumatica raises the message:

“GL Error: The financial period cannot be specified because the branch has not been specified in the Branch box.”

Set the BranchID first, then insert the document.

Avoid setting FinPeriodID manually unless it is required. Acumatica will default the correct period based on the branch and transaction date.

If the financial period must be specified explicitly, it should be assigned after the document is inserted (and then updated), once the Branch context is established.


  • Freshman I
  • January 21, 2026

For info - In my instance, it turned out that AccessInfo.BranchID on my INTransferEntry graph instance was null. This seems to be because my code is running in a webhook using PXLoginScope. The result was that the financial period validation in the graph was failing.

I was able to resolve my issue by setting the branch ID before instantiating my graph instance, as follows:

PXLogin.SetBranchID(cBranchID);  


Hello ​@mauritzv ,

I think you should reference the correct data view before setting the branch, and then update the record after assigning the value.
As you can see, the data view for the branch is CurrentDocument.
It should be implemented like this:

Also, try to update the branch in the transfer during the first part of the update process.

 

 


harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+4

hi ​@mauritzv,

Are you sure on the branchID= 1? can you watch if the branch id gets a value after that and is not empty before putting the finperiod?

Hello ​@mauritzv ,

As there are already several comments here, I just wanted to briefly confirm that I ran your code without making any changes (other than adjusting the BranchID), and it worked perfectly. I fully agree with ​@npetrosov31 ’s conclusion that the issue appears to be related to an incorrect BranchID.

I recommend double-checking the BranchID of the RBYTEMAIN branch directly in SQL to confirm.
If that resolves the issue, please mark ​@npetrosov31’s answer as the accepted solution rather than mine 🙂