从Ax 2012列表页面(EP)多重选择下载文档.aspx

时间:2016-09-16 13:46:17

标签: c# asp.net axapta dynamics-ax-2012 enterprise-portal

我一直在努力解决这个问题,但似乎无法找到解决问题的方法。如果可能的话,我真的希望得到一些帮助,这对我来说意义重大。

我目前正在企业门户网站网站上运行ax 2012的列表页面,该网站允许用户选择发票,然后点击开始下载生成的发票PDF的按钮。 它看起来像这样: enter image description here

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

downloadDocument.aspx获取Websession和axaptasession,并提取在Ax ListPage中选择的单个记录。 downloadDocument.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以创建必要的文档并将其发送给用户。

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

1 个答案:

答案 0 :(得分:0)

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

 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);