Notifications
Announcements
No record found.
Hi All,
How can i create a new computed column and adding view method using extension in d365fo?
Thanks in advance.
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).
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.
[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.
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.
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.
Hi Rusty Ryan,
I have modified your logic to T-SQL and you can use this in computed column,
Please verify the answer if it helps you
Thanks Debugger. It's Working.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 659 Most Valuable Professional
André Arnaud de Cal... 533 Super User 2025 Season 2
Sohaib Cheema 289 User Group Leader