Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

create a field on the form based on the view's field

Posted on by 768

Hello,

 Could you please help me AX stars? I have a form which has got a field an itemName field. It's got via display method and actually it contains field Name from table ecoresproducttranslation.  I can't filter it. I was tasked to recreate the same field but so that I can filter it. It's done via creation of the view as I read. Please see correlations between fields in design and form fields (sorry for russian labels).

1385.111.JPG

Also form contains a field InventSum_ItemId. It's a field ItemId from table InventSum. I created a view which contains the needed field Name from ecoresproducttranslation table and ItemId. Now I need to somehow connect filed ItemId from my view and ItemId from the form so that I could see the correct Name field on the form. I've read that it's done via init() method of the form

I've read the following code:

itemNameAzat_ds.query().dataSourceTable(tableNum(itemNameAzat)).relations(false);
 itemNameAzat_ds.query().dataSourceTable(tableNum(itemNameAzat)).addDataSource(tableNum(InventSum)).addLink(fieldNum(InventSum, ItemId),fieldNum(itemNameAzat,ItemId));
info(itemNameAzat_ds.query().dataSourceNo(1).toString());


But it takes multiple records because field ItemId is repeating in the InventSum table.

3513.114.JPG

That's not what I expect but I understand why it happens. The query works fine. Simply not what I need. I need the highlighted column gives the same values as the left one next to it. But I also don't understand why field ItemId from inventSum table on the form shows unique values? IN the original table there are repeating values. Please see below

I hope I've explained the things clear enough. Please feel free to ask any info.

Many thank sin advance.

*This post is locked for comments

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: create a field on the form based on the view's field

    You are a super star) Many many thanks^) you've saved my life)  Worked like magic for me) the only thing to mention. I haven't found modifyQueryBasedOnDatasourceName() method in the class InventDimCtrl_Frm_OnHand as you can see on the left pane of the screenshot. Therefore I have changed in the method modifyQuery(). I have added the highlighted in yellow string and everything worked fine as expected.

    3122.InventOnhandItem.jpg

    3122.InventOnhandItem.jpg

    As I see the form "В наличии" involves so many methods and classes to build a conclusive form. Could you please help to understand what is the best approach to understand how form is built from scratch? I've tried via breakpoints and I've figured out how particular values of the fields are got but I don't have a complete and full understanding of how forms are formed. For instance the class you mentioned, I didn't know about it.

    Thank you.

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: create a field on the form based on the view's field

    Thank you very much for all your answers. But actually I need to achieve the result by means of the view. I have created a view called "itemNameAzat". It contains two fields "ItemId" and "Name". The "Name" is the field I need on my form "В наличии". I have tried to create a sample (test) form with 2 datasources - "InventSum" table and "itemNameAzat" view. Then I have added to init method of the "itemNameAzat" datasource the following code:

    public void init()
    {
        super();
        this.query().dataSourceTable(tablenum(itemNameAzat)).addLink(fieldnum(InventSum, ItemId), fieldNum(itemNameAzat, ItemId));
    }

    So I have added a link between datasources. Then I've set join source of "itemNameAzat" view to "InventSum" and LinkType - Innerjoin and bingo! I got what I wanted:

    InventOnhandItem.jpg

    It is the correct relation between my view and "InventSum" table.

    But when I do exactly the same on the form "В наличии" (inventOnhandItem) I really need (not the sample) -  I got nothing but empty values in the "Name" field.

    InventOnhandItem.jpg

    Could you please help to understand what's wrong? The sample form works and the needed one doesn't. Please help me to figure out this. Really appreciate your help here!!! Thank you very much

  • Verified answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: create a field on the form based on the view's field

    Take a look at InventDimCtrl_Frm_OnHand class and modifyQueryBasedOnDatasourceName() method.

    You should add groupBy field like NameAlias from InventTable (line 131).

  • dark_knight Profile Picture
    dark_knight 768 on at
    RE: create a field on the form based on the view's field

    Hello,

    Do I need to create additional relations between tables? I mean between EcoResProductTranslation  and InventTable? If yes I did so by common field "Product" and I have added relation to EcoResProductTranslation table. Then I have added table EcoResProductTranslation to data sources of the form and then in the properties I have chosen JoinSource - InventTable DS and Link Type - InnerJoin. Then I have added field "Name" from EcoResProductTranslation  to the grid and nothing. Empty values there in the field "Name" on the form.

  • Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: create a field on the form based on the view's field

    Hi dark_knight!

    Try to add EcoResProductTranslation table as DS of the form and join it to InventTable_DS. Then use the field from EcoResProductTranslation instead of display method.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans