在Acumatica中从数据视图打印重复记录。

问题描述 投票:0回答:1

我试图在Acumatica中使用一个for循环将一个数据视图的所有记录打印到一个文件中。不幸的是,我每次都以打印第一条记录结束,导致记录重复,无法跟踪我哪里出了问题......请协助。

我的代码来了.......

public class MayBankGIROProcess : PXGraph<MayBankGIROProcess>
{
        public PXSelect<MayBankGIRO> Document; //This is my Data View
        public PXAction<MayBankGiroFilter> createTextFile;
        [PXUIField(DisplayName = "Create Text File")]
        [PXButton()]
        public virtual IEnumerable CreateTextFile(PXAdapter adapter)
        {          
            List<string> myList = new List<string> { };
            foreach (MayBankGIRO dacRecord in this.Document.Select()) //this is the loop which is taking the data records.
            {
                myList.Add(dacRecord.ReordType+ "|"+ dacRecord.CustomerReferenceNumber+ "|"+ dacRecord.ClientBatchID+ "|");
                // The above line is printing only the first record of the data view everytime .
            }

            string filename = "DAWN" + ".txt";
            Download(myList, filename);
            return adapter.Get();
        }

        public static void Download(List<string> lines, string name) //method generating file
        {
            var bytes = default(byte[]);
            using (MemoryStream stream = new MemoryStream())
            {
                StreamWriter sw = new StreamWriter(stream);
                foreach (string line in lines)
                {
                    sw.WriteLine(line);
                }

                stream.Position = 0;
                bytes = stream.ToArray();

                sw.Close();
            };
            PX.SM.FileInfo textDoc = new PX.SM.FileInfo(name, null, bytes);

            if (textDoc != null)
            {
                throw new PXRedirectToFileException(textDoc, true);
            }
            else
            {
                PXTrace.WriteInformation("Could not generate file");
            }
        }
}

[Generated Text File with all duplicate Record][1]
[1]: https://i.stack.imgur.com/Kllmk.png
[Original Record from database][2]
[2]: https://i.stack.imgur.com/Rbr9k.png

acumatica
1个回答
0
投票

这通常发生在报表从一个没有定义唯一键的SQL视图DAC中提取时。在DAC字段上添加IsKey=True,直到SQL视图拉取唯一的记录,这个错误应该会消失。

© www.soinside.com 2019 - 2024. All rights reserved.