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, ...
Unanswered

Unit convertion in Computed Column to use in Query

(0) ShareShare
ReportReport
Posted on by

Good day everyone, 

I am creating a form, which will be used for matching purchase and sales line.

This form needs to present the list of matching purchase candidates for a SalesLine comparing quantity with purchase lines.
From sales order form we can select the sales line and then click menu action button to open my form show matchable candidates.

This is a form with a grid and behind it is a query with a PurchLine as a main datasource.

The matching is done using quantity, when SalesLine.SalesQty == PurchLine.PurchQty we need to show this line, but, of course, lines can have different units and we need to implement unit conversion there.

For sales line with 100 * UnitId kilograms the form should show all PurchLines candidates which have 100 kg or even 0.1 ton or even 100 000 grams.

And that is a problem I do not know how to add the convertion to my form.

Unfortunatelly we need performance and we cannot use some Tmp table which we would pre-fill upon openning with converted values.

Is there any option how I can tell SQL to do the magic for me using Computed Columns or join some View which will convert all quantities to the UnitId I specify?
Or simply: Can I do the unit convertion using Computed column?

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi Volodymyr2127,

    For convertion  you can check UnitOfMeasureConverter_Product class.

    UnitOfMeasureConverter_Product unitConverter  = UnitOfMeasureConverter_Product::construct();
    unitConverter.parmProduct(InventTable::find("Test",true).Product);
    unitConverter.parmFromUnitOfMeasure(UnitOfMeasure::unitOfMeasureIdBySymbol("g"));
    unitConverter.parmToUnitOfMeasure(UnitOfMeasure::unitOfMeasureIdBySymbol("kg"));

    A computed column method  it returns a piece of T-SQL code for the calculation. The method is executed on database synchronization and the piece of T-SQL code is inserted to the view definition.

    If you want to use computed columns, your need to prepare SQL code that you want to generate.

    Obviously can't use X classes (such as UnitOfMeasureConverter) in SQL.

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

    The logic for conversions is pretty complicated; rewriting it to T-SQL (and then writing X++ code generating this T-SQL code) wouldn't be a huge task. I don't think it's worth it.

    By the way, which version of AX are you talking about?

  • Community Member Profile Picture
    on at

    Dynamics 365 F&O 10.0.12

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans