26

我已经为此苦苦挣扎了一段时间,似乎无法为我的问题找到解决方案。如果可能的话,我真的很想在这里得到一些帮助,这对我来说意义重大。

我目前正在企业门户网站上运行 ax 2012的列表页面,该页面允许用户选择发票,然后单击开始下载生成的发票 PDF 的按钮。它看起来像这样: 在此处输入图像描述

按钮EpDocuGetMenuitem(输出菜单项)是指启动静态文件的 URL webMenuItem downloadDocument.aspx

downloadDocument.aspx获取 Websession 和 axaptasession 并提取在 Ax 中选择的单个记录ListPagedownloadDocument.aspx有以下代码:

<%@ Page Language="C#" Trace="false" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Portal, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Data.Ax, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.BusinessConnector, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.BusinessConnector.Proxy, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Metadata.AX, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.Portal" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.Portal.UI" %>
<%@ Import Namespace="Microsoft.Dynamics.AX.Framework.Portal.Data" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Proxy" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Session" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Adapter" %>
<%@ Import Namespace="Microsoft.Dynamics.AX.Framework.Services.Client" %>
<%@ Register TagPrefix="dynamics" TagName="EPSecurityControl" src="EPSecurityControl.ascx" %>
<dynamics:EPSecurityControl ID="AxEPSecurity" runat="server" /> 
<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        AxSharepointWebSession session = null;
        try
        {
            session = SessionHelper.Instance.GetSharepointSession();

            if (session != null)
            {
                using (EPDocuGet doc = new EPDocuGet(session.AxaptaAdapter))
                {
                    // EPDocuGet writes directly to the output stream
                    AxQueryString query = new AxQueryString(this.Request);
                    if (query.RecordContext != null)
                    {
                        AxTableContext tableContext = AxTableContext.Create(session, query);
                        if(tableContext != null && tableContext.DataKey != null)
                        {
                            using (IAxaptaRecordAdapter record = tableContext.DataKey.GetRecords(session))
                            {
                                if (tableContext.TableId == TableMetadata.TableNum("DocuRef"))
                                {
                                    doc.runDownload(record);

                                }
                                else
                                {
                                    // Run a report using the Client SDK UserImpersonationContext to revert the credentials from EP application pool to the authenticated user
                                    using (new UserImpersonationContext())
                                    {
                                        doc.runDownload(record);
                                    }
                                }
                            }
                        }
                    }
                }

                Response.Flush();
            }
        }
        catch (System.Exception)
        {
            // Current design is to not display errors to the user

            // Errors are stored in the event log for review by the site operator
        }
        finally
        {
            if (session != null)
            {
                SessionHelper.Instance.ReleaseSharepointSession(session);
            }
        }
    }
</script>

文件中有趣的部分是这段代码:

using (EPDocuGet doc = new EPDocuGet(session.AxaptaAdapter))
{
    // EPDocuGet writes directly to the output stream
    AxQueryString query = new AxQueryString(this.Request);
    if (query.RecordContext != null)
    {
        AxTableContext tableContext = AxTableContext.Create(session, query);
        if (tableContext != null && tableContext.DataKey != null)
        {
             using (IAxaptaRecordAdapter record = tableContext.DataKey.GetRecord(session))
             {
                 if (tableContext.TableId == TableMetadata.TableNum("DocuRef"))
                 {
                       doc.runDownload(record);
                 }
                 else
                 {
                      // Run a report using the Client SDK UserImpersonationContext to revert the credentials from EP application pool to the authenticated user
                      using (new UserImpersonationContext())
                      {
                           doc.runDownload(record);
                      }
                 }
             }
        }
    }
}

这里的目标是让所有选定的记录在downloadDocument.aspx. 我在 Ax 中启用了多选,所以我想应该可以以某种方式获取所有记录。我认为这个片段应该有所不同

IAxaptaRecordAdapter record = tableContext.DataKey.GetRecord(session)

但我无法弄清楚。

如果我可以获取downloadDocument.aspx文件中的所有记录,我可以将字符串发送回 ax 以创建必要的文档并将它们发送给用户。

关于如何做到这一点的任何建议?

4

1 回答 1

1

前段时间我有类似的要求。尝试使用此代码段。请注意,这会为每个标记的行调用 ax 方法。可能有一种更有效的方法来发送整个数据集。

 IReadOnlySet<DataSetViewRow> rows     = this.ds_yourDSName.GetDataSourceView("YourDSName").DataSetView.GetMarkedRowsSet();
 IEnumerator<DataSetViewRow> enumRows  = rows.GetEnumerator(); 


        while (enumRows.MoveNext())
        {
            //code to get fields needed
            //call to a static ax method to send the fields as parms
            this.AxSession.AxaptaAdapter.CallStaticClassMethod("ClasName","MethodName", parm1, parm2);
        }

        DialogHelper.Close(CloseDialogBehavior.RefreshDataSource);
于 2018-04-12T08:40:38.513 回答