最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

D365: Create lookup in X++

网络文摘 William 1739浏览 0评论

Product:

Dynamics 365 for Finance and Operations

Purpose:

The purpose of this document is to demonstrate how we can create a lookup in X++ and attach it to an extension field added to the form extension of standard Sales order form. This is a good example to see how we can use event handling to achieve our goal without modifying the standard code.

Business requirement:

Display contacts of the customer in a lookup for which the sales order has been raised.

Development:

You can find the event handler below which handles the lookup event of a form control. This form control is added to the extension of SalesTable standard AX form.
[FormControlEventHandler(formControlStr(SalesTable, SixSalesOrderConfirmation_SixCustContactPersonId),
	FormControlEventType::Lookup)]
public static void SixSalesOrderConfirmation_SixCustContactPersonId_OnLookup(FormControl sender, FormControlEventArgs e)
{
	Query query;
	QueryBuildDataSource qbdsContactPerson;
	QueryBuildDataSource qbdsCustTable;
	QueryBuildDataSource qbdsSalesTable;
	SysTableLookup sysTableLookup;
	SalesId salesId;
	FormControlCancelableSuperEventArgs event;

	event = e as FormControlCancelableSuperEventArgs;
	salesId = sender.formRun().design().controlName(formControlStr(SalesTable, SalesTable_SalesId)).valueStr();

	query = new Query();
	qbdsContactPerson = query.addDataSource(tableNum(ContactPerson));

	qbdsCustTable = qbdsContactPerson.addDataSource(tableNum(CustTable));
	qbdsCustTable.joinMode(JoinMode::InnerJoin);
	qbdsCustTable.relations(false);
	qbdsCustTable.addLink(
		fieldNum(ContactPerson, ContactForParty),
		fieldNum(CustTable, Party));

	qbdsSalesTable = qbdsCustTable.addDataSource(tableNum(SalesTable));
	qbdsSalesTable.joinMode(JoinMode::InnerJoin);
	qbdsSalesTable.relations(false);
	qbdsSalesTable.addLink(
		fieldNum(CustTable, AccountNum),
		fieldNum(SalesTable, CustAccount));

	qbdsSalesTable.addRange(fieldNum(SalesTable, SalesId)).value(SysQuery::value(salesId));

	sysTableLookup = SysTableLookup::newParameters(tableNum(ContactPerson), sender);
	sysTableLookup.addLookupfield(fieldNum(ContactPerson, ContactPersonId));
	sysTableLookup.addLookupfield(fieldNum(ContactPerson, Party));
	sysTableLookup.parmQuery(query);
	sysTableLookup.performFormLookup();

	event.CancelSuperCall();
}
 
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址