简体   繁体   English

如何使用 X++ 根据其他字段自动填充字段?

[英]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.

相关问题 如何使用 x++ 从字符串字段自动填充查找字段? - How can I auto populate a lookup field from a string field with x++? 如何使用jscript OnLoad事件使用来自父记录的数据自动填充QuickCreate表单字段? - How can I auto-populate QuickCreate form fields with data from a parent record using a jscript OnLoad event? 如何根据文本字段填充查找字段 - Dynamics 365 - How to populate look up field based on text field - Dynamics 365 CRM自动填充选项集中的字段 - CRM Auto Populate Field From Option Set Dynamics 365 - 如何根据所选产品从不同实体中检索记录并填充字段? - Dynamics 365 - How to retrieve record and populate in field from different entity based on selected product? 如何根据特定条件自动更新CRM实体的“状态原因”字段? - How to auto-update a “Status Reason” field of a CRM entity, based on specific condition? 如何在客户端动态填充查找字段 - How to populate lookup field dynamically in client side 在CRM 2011中创建后使用工作流自动填充表单字段 - Using a Workflow to auto-populate a form field upon creation in CRM 2011 当查找中仅存在1个值时,在CRM 365中自动填充查找字段 - Auto Populate Lookup Field in CRM 365 when only 1 value exists in Lookup CRM插件:将一个字段的值计算为其他两个字段之间的差 - CRM Plugin: Calculate the value of a field as the difference between two other fields
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM