1

I have a big question, you can attach XML through an action, when you import the XML and also save it in the "Files" tab, the question is. if it can be attached?.

Here is an example image: what is missing is that I automatically attach in the "Files" tab, when I put upload

Here I have an example image

Here is my code where, I attached the XML

  public PXAction<ARInvoice> CargarXML;
    [PXUIField(DisplayName = "Carga de código hash")]
    [PXButton()]
    public virtual void cargarXML()
    {
        var Result = NewFilePanel.AskExt(true);
        if (Result == WebDialogResult.OK)
        {
            PX.SM.FileInfo fileInfo = PX.Common.PXContext.SessionTyped<PXSessionStatePXData>().FileInfo["CargaSessionKey"];
            string result = System.Text.Encoding.UTF8.GetString(fileInfo.BinData);

            ARInvoice ari = Base.Document.Current;
            xtFECodHashEntry graph2 = PXGraph.CreateInstance<xtFECodHashEntry>();
            var pchExt = ari.GetExtension<ARRegisterExt>();

            string Valor = "";
            XmlDocument xm = new XmlDocument();
            xm.LoadXml(result);

            XmlNodeList elemList = xm.GetElementsByTagName("ds:DigestValue");
            for (int i = 0; i < elemList.Count;)
            {
                Valor = (elemList[i].InnerXml);
                break;
            }
            PXLongOperation.StartOperation(Base, delegate ()
            {
                xtFECodHash dac = new xtFECodHash();
                dac.RefNbr = ari.RefNbr;
                dac.DocType = ari.DocType;
                dac.Nrocomprobante = ari.InvoiceNbr;
                dac.Hash = Valor;
                dac.Tipo = pchExt.UsrTDocSunat;
                graph2.xtFECodHashs.Insert(dac);
                graph2.Actions.PressSave();
            });
        }
    }
Tibu
  • 31
  • 1
  • 8

1 Answers1

1

If you have the FileInfo object which it seems like you do I have used something like this:

protected virtual void SaveFile(FileInfo fileInfo, PXCache cache, object row)
{
    if (fileInfo == null)
    {
        return;
    }

    var fileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();

    if (!fileGraph.SaveFile(fileInfo, FileExistsAction.CreateVersion))
    {
        return;
    }

    if (!fileInfo.UID.HasValue)
    {
        return;
    }

    PXNoteAttribute.SetFileNotes(cache, row, fileInfo.UID.Value);
}

So in your example you could call this method as shown above using the following:

SaveFile(fileInfo, Base.Document.Cache, Base.Document.Current);
Brendan
  • 5,428
  • 2
  • 17
  • 33