Skip to main content
Solved

Read Xml file

  • June 14, 2023
  • 1 reply
  • 110 views

Forum|alt.badge.img

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.

 

 

Best answer by davidnavasardyan

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.

View original
Did this topic help you find an answer to your question?

davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+2

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings