Solved

Read Xml file

  • 14 June 2023
  • 1 reply
  • 78 views

Userlevel 3
Badge

Hi,

I have requirement to read data from xml file and insert the data into the custom table.

This xml file is daily updated into the location.So,I need to automated the process.

Anyone can suggest resources or workaround for that.

 

 

icon

Best answer by davidnavasardyan09 28 June 2023, 18:01

View original

1 reply

Userlevel 5
Badge +1

Hello @jeewanishalika20 

Acumatica allows for automating these kinds of tasks. I suggest you implement a scheduled processing screen for this, where you can read the XML file and insert its data into the custom table. Here's a general guideline to achieve this:

  1. Create a Processing Graph: First, you need to create a Processing graph (which extends PXGraph) with an action that reads the XML file and writes its contents into your custom table.
public class ReadXMLProcess : PXGraph<ReadXMLProcess>
{
public PXCancel<XMLFile> Cancel;
public PXProcessing<XMLFile> Files;

public ReadXMLProcess()
{
Files.SetProcessDelegate(ProcessFile);
}

public static void ProcessFile(List<XMLFile> files)
{
foreach (var file in files)
{
// Add logic to read XML file, deserialize it into a class,
// and then insert data into your custom table

// You can use System.Xml.Serialization.XmlSerializer to deserialize XML
// and use PXCache to insert into your custom table
}
}
}
  1. Create a DAC to Represent the XML File: You might need a Data Access Class (DAC) to represent the XML file or its entries.
[Serializable]
public class XMLFile : IBqlTable
{
#region FileID
public abstract class fileID : PX.Data.BQL.BqlInt.Field<fileID> { }
[PXDBIdentity]
public virtual int? FileID { get; set; }
#endregion

#region FileName
public abstract class fileName : PX.Data.BQL.BqlString.Field<fileName> { }
[PXDBString(200, IsUnicode = true)]
[PXUIField(DisplayName = "File Name")]
public virtual string FileName { get; set; }
#endregion

// Add other fields needed to represent your XML file
}
  1. Schedule the Process: In Acumatica, you can schedule your process to run at specific intervals. You can do this from the Automation Schedules (SM205020) screen. Use your processing graph (ReadXMLProcess) and set the desired frequency.

  2. Read XML and Insert into Custom Table: You need to implement the logic to read the XML file and insert its data into your custom table within the ProcessFile delegate.

To read the XML file, you can use the System.Xml.XmlDocument class or System.Xml.Linq.XDocument class in .NET. You would typically read the file into a string or Stream, load that into the XmlDocument or XDocument, and then query the data you need using XPath or LINQ to XML.

To insert data into the custom table, use the Insert method on the PXCache object for your custom DAC. You get the PXCache object by calling this.Caches[typeof(YourDAC)] in your graph.

  1. Automation of File Retrieval: The files are updated daily in a certain location. If this location is accessible by Acumatica, you can automate the retrieval of these files as part of your scheduled process. If the location is not directly accessible by Acumatica, you may need an external script or process to move or copy the files into a location that Acumatica can access.

This is a general outline of the process and you would need to customize it to fit your needs. Ensure to add appropriate error handling and reporting so you can track the process and handle any issues that arise.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved