Skip to main content

In Batch Payment (AR305000) how can i export xml file include Reference Nbr, payment date, payment method using grid button. any one know solution ?

 

Hi,

If, you are looking for something that is user driven (ie. the user clicks a button and is able to download a file) I would consider a customization which creates a file and stores it in the file system.  There is a good article on how to do this here:  https://www.acumatica.com/blog/attachment-files/

And a code snippet below:

 UploadFileMaintenance graph = PXGraph.CreateInstance<UploadFileMaintenance>();

               FileInfo file = new FileInfo(Guid.NewGuid(),
                                                       sFileName,
                                                       null,
                                                       Encoding.UTF8.GetBytes("insert string containing XML here");
               PXNoteAttribute.AttachFile(cache, target, file);
               
               graph.SaveFile(file);

               UploadFile upload = new UploadFile();
               upload.FileID = file.UID;
               upload.Name = sFileName;
               upload.Versioned = false;

               graph.Files.Insert(upload);
               graph.Actions.PressSave();

 

You need to include using PX.SM at the top of your file.

This solution a couple of extra mouse clicks that is ideal (ie. click button to run the code above, click files, click link to download, but it will accomplish what you have described as the objective

 

 

Also, I would think about why you are wanting to generate the XML file.  Presumably this is to be used as an input into something else?  Maybe consider using the inbuilt Acumatica API functionality to put together something that generates and XML file.

 

Thanks,

John.

 

 

 


Hi,

 

You might also be able to add in a PXRedirectToFileException to avoid the need for the user to open the Files dialog and click the link to download the XML file.  There is some additional info here:

 

And the below suggests that if you use the right file extension you might be able to get the download to trigger automatically:

 

 


This is the answer

public PXAction<PX.Objects.CA.CABatch> Attach;

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Attach")]
protected virtual IEnumerable attach(PXAdapter adapter)
{
// Use your favorite library to create XML file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null));

// Create root node of XML file
XmlNode rootNode = xmlDoc.CreateElement("GridData");

// Iterate rows of the DataView
foreach (CABatchDetail dacRecord in Base.BatchPayments.Select())
{
// Create an XML Element to represent the DAC row
XmlNode xmlDACRecord = xmlDoc.CreateElement("DACRecord");

// Add desired DAC fields as child XML Elements of the DAC row XML element
XmlNode xmlDACField1 = xmlDoc.CreateElement("DACField1");
xmlDACField1.AppendChild(xmlDoc.CreateTextNode(dacRecord.OrigRefNbr.ToString()));
xmlDACRecord.AppendChild(xmlDACField1);

XmlNode xmlDACField2 = xmlDoc.CreateElement("DACField2");
xmlDACField2.AppendChild(xmlDoc.CreateTextNode(dacRecord.OrigDocType.ToString()));
xmlDACRecord.AppendChild(xmlDACField2);

// Adding XML DAC Record to XML root node
rootNode.AppendChild(xmlDACRecord);
}

// Adding XML root node to XML document
xmlDoc.AppendChild(rootNode);

// Redirect browser to XML file created in memory on server
throw new PXRedirectToFileException(new PX.SM.FileInfo(Guid.NewGuid(),
"filename.xml",
null,
System.Text.Encoding.UTF8.GetBytes(xmlDoc.OuterXml)),
true);

return adapter.Get();

 


Reply