Skip to main content

Good day,

I was wondering if someone could help me identify the reason for an error I am having when I insert CustomerLocationID creating an invoice. I receive data from a SOAP API endpoint, and I have a method to create customers and Locations if they don’t exist in acumatica to insert them on their corresponding fields. After my code verifies if the first Location exists and creates the new location or if already existed, just assigns it to CustomerLocationID field, it creates the first invoice successfully, but from there the second invoice gives an error that says there was a problem processing the field Location value “Any Location” Location cannot be found in the system.

I don’t understand why the error says cannot be found in the system, when I check Customer Locations in Acumatica, it did create the new Location, and if I try to create the invoice manually with that Location, it saves with no problem.

 

the first fragment of code is the class where I create the invoice and the second one is the class where I create the location if it doesn't exist.

 .   .   .   .
var graphIn = PXGraph.CreateInstance<SOInvoiceEntry>();

//Grouping tickets by customer,project and Order
var result = from headerin in tickets

group headerin by new { headerin.CustomerID, headerin.ProjectCode,
headerin.OrderCode } into g
orderby g.Key.CustomerID, g.Key.ProjectCode
select new { CustomerID = g.Key.CustomerID, ProjectCode = g.Key.ProjectCode, OrderCode = g.Key.OrderCode };

foreach (var grouped in result)
{
. . . .
//verify if location exists
Location location = null;
location = SelectFrom<Location>.Where<Location.locationCD.IsEqual
<@P.AsString>>.View.SelectSingleBound(graphIn, null, grouped.ProjectCode);

if(location == null)
{
ProjectCreation.CreateProject(grouped.ProjectCode, customer.BAccountID);
}
else
{
ProjectLocationID = location.LocationID;
}

//Inserting in invoice header
ARInvoice arin = new ARInvoice
{

CustomerID = customer.BAccountID,
CustomerLocationID = ProjectLocationID,
DocDate = DateTime.Parse(createdDate),
InvoiceNbr = grouped.OrderCode

};


graphIn.Document.Cache.Insert(arin);
. . . .

graphIn.Actions.PressSave();
 public static void CreateProject(string Code, int? CustomerID)
{
. . . . .
var graphCL = PXGraph.CreateInstance<CustomerLocationMaint>();
var projects = rec.WebcreteXMLMsgsRs.ProjectQueryRs;
ProjectRet project = projects.Find(p => p.Code == Code);


Location lctn = new Location
{
BAccountID = CustomerID,
LocationCD = Code.Trim(),
Descr = project.Name.Trim(),

};
graphCL.Location.Cache.Insert(lctn);

Address address = new Address
{
AddressLine1 = project.DeliveryAddress.Addr1,
AddressLine2 = project.DeliveryAddress.Addr2,
City = project.City,
State = project.State,
PostalCode = project.PostalCode,
CountryID = "US"
};
graphCL.Address.Cache.Insert(address);
Contact contact = new Contact
{
ContactType = "AP",
FullName = project.CustomerName,
EMail = project.Email,
DisplayName = project.CustomerName,
BAccountID = CustomerID

};
graphCL.Contact.Cache.Insert(contact);
graphCL.Actions.PressSave();


Location locations = null;
locations = SelectFrom<Location>.Where<Location.locationCD.IsEqual
<@P.AsString>>.View.SelectSingleBound(graphCL, null, Code);
ProjectLocationID = locations.LocationID;



EVTCInvokeProcess.ProjectLocationID = ProjectLocationID;

 

Hi @orlandonegron43,

Please refer to the code snippet below. I have not tested it, but it might be helpful.

graphCL.Actions.PressSave();
graphCL.Persist();

Location lctn = graphCL.Location.Current; // Retrieve the newly inserted Location record

if (lctn != null)
{
ProjectLocationID = lctn.LocationID;
}

Make sure it is a valid LocationID and not null.

 

Regards,

Sweta


Reply