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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

X++ Convert computed column in D365Fo

(0) ShareShare
ReportReport
Posted on by 351

Hi all,

I have a one display method and that display method i want to use in view without display method.

I want to convert display as computed column in view please give me that.

Code:-

display Description getCodeAllLanguage()
    {
        str                       userlanguage = currentUserLanguage();
        Description            code;
        TDLLine                   lines;
        Translator                translator;
        TDLAccruals               accruals;
        str  fieldName           = fieldId2Name(tableNum(TDLAccruals), fieldNum(TDLAccruals, AccrualID));

        select firstonly RecId, TranslatedText from translator
        where  translator.DataArea  ==  curExt()
        &&  translator.RefTableId == tableNum(TDLAccruals)
        &&  translator.LanguageId == userlanguage
        &&  translator.FieldName == fieldName
        join accruals
        where accruals.AccrualID== this.Code
        && translator.AccrualID == accruals.RecId;
        
   
        if(!translator.RecId)
        {
            code = this.Code;
        }
        else
        {
            code = translator.TranslatedText;
        }

        return code;
    }
 

Thanks 

I have the same question (0)
  • GirishS Profile Picture
    27,843 Moderator on at

    Hi,

    You can take a look at the standard view "HcmWorkerActiveFixedCompCumulativePayAmtMSTView".

    Thanks,

    Girish S.

  • waytod365 Profile Picture
    351 on at

    Thanks for your replay girishS,

    I'm not aware of T-SQL. could you please convert normal method in view if you can.

  • waytod365 Profile Picture
    351 on at

    Hi, i tried computed column below code not working.

    ublic static Str getCodeAr()
        {
            str                       userlanguage = currentUserLanguage();
            str pay = SysComputedColumn::returnField(viewstr(TDLLines ),identifierStr(TDLLine ),fieldStr(TDLLine , Code));
               
            Str60         code;
            
            Translator              translator;
            TDLAccruals               accruals;
            str  fieldName           = fieldId2Name(tableNum(TDLAccruals), fieldNum(TDLAccruals, AccrualID));
    
            select firstonly RecId, TranslatedText from translator
            where  translator.DataArea  ==  curExt()
            &&  translator.RefTableId == tableNum(TDLAccruals)
            &&  translator.LanguageId == userlanguage
            &&  translator.FieldName == fieldName
            join accruals
            where accruals.AccrualID== pay
            && translator.AccrualID == accruals.RecId;
           
            
             if(!translator.RecId)
            {
                code = this.Code;
            }
            else
            {
                code = translator.TranslatedText;
            }
            
            
            
    
            return pay;
        }

    Note : I have only one dataSource in the view don't wanna add multiple. also if condition computed column how to do ? please give me example for that ?

    Thanks  

  • waytod365 Profile Picture
    351 on at

    return code not pay its my bad. code return also not working

  • Verified answer
    André Arnaud de Calavon Profile Picture
    306,446 Super User 2026 Season 1 on at

    Hi Waytod365,

    You can start with reading the documentation and see if you can learn from it.

    Walkthrough: Add a Computed Column to a Union View | Microsoft Docs

    Walkthrough: Add a Computed Column to a View | Microsoft Docs

  • Martin Dráb Profile Picture
    240,177 Most Valuable Professional on at

    The whole purpose of a computed column is generating a piece of T-SQL code, which becomes a part of the SQL view.

    Therefore you can't meaningfully say that you want "normal" code instead of T-SQL.

    And the fundamental problem with your code is that it doesn't do the right thing at all. It doesn't generate T-SQL code for getting the value.

  • waytod365 Profile Picture
    351 on at

    Thanks for your replay martin sir,

    i do agree with you sir.

    The thing is i want to same display method bring to view as new method so that there is need to do computed column and the same display method if condition and some thing i don't know how to check computed column.

    Note : That view only one DataSource (TDLLines) : view name : TDLLine.

    Would be great if you could example then i learn about that.

    Thanks.

  • Verified answer
    Martin Dráb Profile Picture
    240,177 Most Valuable Professional on at

    Before you can write X++ code that will generate your T-SQL code, you need to know what T-SQL code you want to generate. Therefore forget X++ for a moment and write and test T-SQL.

    You said you're not familiar with T-SQL, therefore either learn the basics or find a colleague who can do this part for you.

    Note that your current code also depends on curExt() and currentUserLanguage(), which is a bug in your design. These things makes no sense in SQL Server, and if you used them in the computed column method, they would be executed on DB synchronization and your computed column would contain a single hard-coded company and and a single language. That's clearly wrong. You need to take the values from other tables in the 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 385 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 270

#3
Martin Dráb Profile Picture

Martin Dráb 243 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans