Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Create View with field...
Finance forum
Suggested answer

Create View with field from display method

Posted on by 707

Hi guys,

Is there a possibility to create View which is the field is from a display method ?

So I create View, lets say the data source is table A and apart from adding fields from table A's field, I also want to have a field that displaying table A's display method.

A sample view from Ax is BankAccountView :

pastedimage1613357085867v1.png

So in this example BankAccountView, I would like the "getBankAccountBalanceCur" to be one of the field.

This is actually related to my other post (+) Relation between ProjTransPosting and ProjPostTransView - Dynamics 365 Finance Forum Community Forum, but it  can be separated so not really matters as the point is still "can we have a field of a View based on a display method ?"

Thanks,

  • Martin Dráb Profile Picture
    Martin Dráb 228,647 Most Valuable Professional on at
    RE: Create View with field from display method

    For reference, amit_s created another thread for his/her actual question.

  • amit_s Profile Picture
    amit_s 65 on at
    RE: Create View with field from display method

    Hi , were you able to get this done ? I have the very same requirement and not sure how to get the display method logic into a T-SQL statement. Any help is appreciated

  • ergun sahin Profile Picture
    ergun sahin 8,812 Moderator on at
    RE: Create View with field from display method

    If there is a no hope, you can create a field for or a table for this and calculate before using view. But you will give up runtime functinalty and it will take a lot time. Like others I think you must create a computed column.

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Create View with field from display method

    There's no workaround if your actual requirement is to create a computed column in the view. But is that your business requirement, or is that just an approach that you chose to fulfill your business requirement?

  • ShaqAX Profile Picture
    ShaqAX 707 on at
    RE: Create View with field from display method

    Hi Martin,

    Yes, understood about the computed column part, also about "The method must return T-SQL code that will calculate the value. The method will be executed on DB synchronization "

    The one that I can't is to interpret what x++ did to all those SysComputedColumn function stuff. "getBankBalanceAccountCur" is not really that complex, even so I don't know how to interpret this. But my real goal is actually the method in ProjPostTransView.proInvoiceStatus(), which is far more complex.

    Any workaround to achieve all this ?

    Thanks,

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,647 Most Valuable Professional on at
    RE: Create View with field from display method

    You misunderstand the purpose of computed columns. The method must return T-SQL code that will calculate the value. The method will be executed on DB synchronization and T-SQL inserted to the view definition in database. It's not your code does - you're trying to return a value of getBankBalanceAccountCur field, which makes no sense.

    You must analyze what getBankBalanceAccountCur() does, rewrite it to T-SQL code and then write X++ code generating this T-SQL code.

    Obviously you can't use X++ code (including getBankBalanceAccountCur() method) in T-SQL.

  • ShaqAX Profile Picture
    ShaqAX 707 on at
    RE: Create View with field from display method

    Hi Ajit,

    Yes, this is what I initially thought, so I create something like this:

    1. In my view, I added this method :

    public static server str projInvoiceStatus()
        {
            DictView    dictView             = new DictView(tableNum(MyView));
            str         projInvoiceStatus     = dictView.computedColumnString('ProjPostTransView', 'projInvoiceStatus', FieldNameGenerationMode::FieldList);
               
        
            return projInvoiceStatus;
        
        }

    over there, ProjPostTransView is my data source in the view, and "projInvoiceStatus" is the display method of ProjPostTransView. 

    2. On the Fields node of that view, add new String computed column and use the method no.1, specified in that field -> View Method property.

    Is this correct ?

    Using my example of BankAccount, is something like this, right ?

    DictView    dictView             = new DictView(tableNum(BankAccountView));
            str         balance = dictView.computedColumnString('BankAccountTable', 'getBankBalanceAccountCur', FieldNameGenerationMode::FieldList);
               
        
            return balance;

    something not really same is this "getBankBalanceAccountCur" on the example is a display method in the view it self while mine, the display method is in the table's side of the data source.

    Thanks,

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Create View with field from display method

    You can add a computed column in a view with your logic.

    docs.microsoft.com/.../walkthrough-add-a-computed-column-to-a-view

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans