Hey*_*gar 25 c# asp.net axapta enterprise-portal dynamics-ax-2012
我一直在努力解决这个问题,似乎无法为我的问题找到解决方案.如果可能的话,我真的希望得到一些帮助,这对我来说意义重大.
我目前正在企业门户网站上运行ax2012的列表页面,该页面允许用户选择发票,然后单击开始下载生成的发票PDF的按钮.它看起来像这样:
按钮EpDocuGetMenuitem
(输出菜单项)指的是启动静态文件的URL webMenuItem downloadDocument.aspx
.
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>
Run Code Online (Sandbox Code Playgroud)
该文件的有趣部分是这段代码:
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);
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里的目标是获取所有选定的记录downloadDocument.aspx
.我在Ax中启用了多选,所以我猜应该可以以某种方式获得所有记录.我假设这个片段应该以某种方式不同
IAxaptaRecordAdapter record = tableContext.DataKey.GetRecord(session)
Run Code Online (Sandbox Code Playgroud)
但我无法弄明白.
如果我可以获取downloadDocument.aspx
文件中的所有记录,我可以将字符串发送回ax以创建必要的文档并将其发送给用户.
有关如何做到这一点的任何建议?
小智 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);
Run Code Online (Sandbox Code Playgroud)