[英]How can I auto populate a field based on other fields with X++?
I am using D365 Finance and operations.我正在使用 D365 财务和运营。 I have a form and four fields in it.
我有一个表格和四个字段。 Every time I enter a new record of one of these three fields, their values should be concatenated and the combined text put to the 'Details' field which is the fourth field.
每次我输入这三个字段之一的新记录时,应将它们的值连接起来,并将组合文本放入第四个字段的“详细信息”字段中。 I think I need to use onupdateevent for this but I do not know-how.
我想我需要为此使用 onupdateevent 但我不知道如何。
I used onmodifyingfield event handler and it works but only when I enter and save the second record.我使用了 onmodifyingfield 事件处理程序,它可以工作,但只有当我输入并保存第二条记录时。 I mean I save record and auto-populate does not work but when I save the second record and refresh the page I can see the auto-populated field in the first record.
我的意思是我保存记录并且自动填充不起作用但是当我保存第二条记录并刷新页面时,我可以在第一条记录中看到自动填充的字段。 Here is my codes;
这是我的代码;
[DataEventHandler(tableStr(InventSite), DataEventType::ModifyingField)]
public static void InventSite_onModifyingField(Common sender, DataEventArgs e)
{
MyTable myTable;
update_recordset mytable setting Details = MyTable.Field1 + ", " + MyTable.Field2;
I would really be appreciated if anyone can help me with this.如果有人可以帮助我,我将不胜感激。
You can attach an event handler to Field1, Field2 and Field3 Modified
events on the form DataSource and when it's triggered simply retrieve the current record, concatenate those values and write them into the Details
field.您可以将事件处理程序附加到表单 DataSource 上的 Field1、Field2 和 Field3
Modified
事件,当它被触发时,只需检索当前记录,连接这些值并将它们写入Details
字段。 The DataSource will then handle inserting or updating all those values into the database record:然后,DataSource 将处理将所有这些值插入或更新到数据库记录中:
[
FormDataFieldEventHandler(formDataFieldStr(InventSite, InventSite, Field1), FormDataFieldEventType::Modified),
FormDataFieldEventHandler(formDataFieldStr(InventSite, InventSite, Field2), FormDataFieldEventType::Modified),
FormDataFieldEventHandler(formDataFieldStr(InventSite, InventSite, Field3), FormDataFieldEventType::Modified)
]
public static void Field1_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
// get the form DataSource
FormDataSource dataSource = sender.datasource();
// get current record
InventSite inventSite = dataSource.cursor();
// contatenate string values
str details = strFmt("%1, %2, %3", inventSite.Field1, inventSite.Field2, inventSite.Field3);
// update field value
inventSite.Details = details;
}
Note: I don't understand what MyTable myTable
buffer is in your code example, but in this case by looking at DataEventHandler
I suppose that all four fields are created in the InventSite
table.注意:我不明白您的代码示例中的
MyTable myTable
缓冲区是什么,但在这种情况下,通过查看DataEventHandler
我想所有四个字段都是在InventSite
表中创建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.