web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Form extension - how do I extend a method containing a query in a standard form?

(0) ShareShare
ReportReport
Posted on by 25

I want to make an extension to the RetailAddItems form to include a custom field, "Test." Other methods in the code for this form call inventTable_ds.executeQuery();, but I can't figure out how to access inventTable_ds in my extended class. Is there another call I could make to retrieve the data for this query? Ultimately, I want to limit the products which show up based on the value of "Test" I pick, as "Test" is a custom field in InventTable.

[ExtensionOf(formControlStr(RetailAddItems, Test))]
final class RetailAddTest_Extension
{

public boolean modified()
{
Query query = new Query();;
boolean ret;

QueryBuildDataSource queryBuildDataSource;

FormDataSource ds;
FormStringControl obj = any2Object(this) as FormStringControl;
FormRun fr = obj.formRun() as FormRun;

queryBuildDataSource = query.addDataSource(tableNum(InventTable));
Query.datasourcetable(tableNum(InventTable)).addrange(fieldNum(InventTable, Test).value(obj.text());

ret = next Modified();
return ret;
}

[Control("String")]
class Vendor
{
public boolean modified()
{
boolean ret;

ret = super();
inventTable_ds.executeQuery();
ecoResProduct_ds.executeQuery();
return ret;
}

}

7711.pastedimage1581375992139v1.png

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: Form extension - how do I extend a method containing a query in a standard form?

    Hi,

    You can access data source via element.InventTable_ds (no brackets).

    To achieve your requirements you probably need 2 extensions:

    1. For control to call InventTable_ds.execute (maybe you would need first to assign the data source to FormDataSource variable and call executeQuery for this variable). Please, note that executeQuery should be run after next statement.

    2. Extension for InventTable formDataSource, to add your filter for InventTable (similar to standard code)

  • Suggested answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: Form extension - how do I extend a method containing a query in a standard form?

    Your code creates a new query, creates a datasource and adds a range - and that's it. The query isn't used anywhere and the object disappears at the end of modified() method without having any effect. Therefore it's the same as not having that code at all.

    What you need to do instead is getting a reference to the query used by the form and manipulate this form. For example: inventTable_ds.queryBuildDataSource().addRange(…).

  • WillWU Profile Picture
    22,361 on at
    RE: Form extension - how do I extend a method containing a query in a standard form?

    Hi dynamics user,

    You can also use event handler(onQueryExecuting) to filter data on form.

    Form ->Data source ->Event-> onQueryExecuting. Past this code in New class and add your code.

    Refer to the following blog:

    www.tech.alirazazaidi.com/.../

    To prevent problems, you can copy the original data source and do these operations on the new one.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 867 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans