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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Computed column method of View using extension

(0) ShareShare
ReportReport
Posted on by 931

Hi All,

How can i create a new computed column and adding view method using extension in d365fo?

Thanks in advance.

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,855 Most Valuable Professional on at

    Implement the computed column method in a class. Then create a view extension, add a computed column and reference the method together with the class name (MyClass::myMethod).

  • Blue Wang Profile Picture
    on at

    Hi Rusty,

    A similar thread : community.dynamics.com/.../d365fo---add-a-computed-column-with-a-new-method-to-an-existing-view-via-extension

    As mentioned, You can create a view extension, then add Computed column and change the attribute "Method" to point to your new method.

  • ThivaKar Profile Picture
    931 on at

    [ExtensionOf(Viewstr(InventTableExpanded))]
    final class Views_Extension
    {
        /// 
        /// To display the sales category.
        /// 
        public static server str  salesCategory()
        {
            ItemId                  itemId;
            EcoResProductCategory   productCategory;
            EcoResCategoryHierarchy categoryHierarchy;
            EcoResProduct           product;
            DictView                dictView;
            EcoResCategory          category;
            
            
            dictView = new DictView(tableNum(InventTableExpanded));
            itemId   = dictView.computedColumnString('InventTable','ItemId',
                                                    FieldNameGenerationMode::FieldList,
                                                    true);
            product           = EcoResProduct::find(InventTable::find(itemId).Product);
            categoryHierarchy = EcoResCategoryHierarchy::findByName('Sales and Marketing');
    
            select * from productCategory
                where productCategory.Product           == product.RecId
                &&    productCategory.CategoryHierarchy == categoryHierarchy.RecId;
    
            category = EcoResCategory::find(productCategory.Category);
    
            return category.Name;
            
        }
    
    }

    Thanks Martin.

    Please check my sample code. I want to show the category name using new computed column in view. Please tell me the possibilities or alternate suggestions.

  • Blue Wang Profile Picture
    on at

    Hi Rusty,

    Have you debugged your code? Does it return the name value correctly?

    If so, then you need to add a string computed column to the extended view, and then set the Method property to Views_Extension :: salesCategory, after that it should work.

    You can follow the link shared above.

  • Suggested answer
    Martin Dráb Profile Picture
    237,855 Most Valuable Professional on at

    Your code makes no sense. A computed column is used to generate T-SQL code that will be embedded in the view definition. It's executed just once, on database synchronization. Therefore the whole idea of calling find() methods etc. is completely wrong. Also, you return a single category name instead of SQL code doing something useful, and therefore your computed is a static value. Now it's empty string, but even if you found a category, the computed column would always return this single category name.

    This is a common misunderstanding and we've discussed it here quite a few times, therefore you can look up older discussions if you need more information.

    Also, you're taking a field name (itemId) and you're trying to find an item with ID equal to the field name. It's surely not what you meant.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Rusty Ryan,

    I have modified your logic to T-SQL and you can use this in computed column,

    pastedimage1582827205900v1.png

    Please verify the answer if it helps you

  • ThivaKar Profile Picture
    931 on at

    Thanks Debugger. It's Working.

  • Martin Dráb Profile Picture
    237,855 Most Valuable Professional on at

    The remaining step is rewriting the code to avoid hard-coded table and field names and the hard-coded hierarchy name.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 659 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 289 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans