Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / X++ Convert computed c...
Finance forum
Answered

X++ Convert computed column in D365Fo

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 

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: X++ Convert computed column in D365Fo

    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.

  • waytod365 Profile Picture
    waytod365 351 on at
    RE: X++ Convert computed column in D365Fo

    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.

  • Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: X++ Convert computed column in D365Fo

    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.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,989 Super User on at
    RE: X++ Convert computed column in D365Fo

    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

  • waytod365 Profile Picture
    waytod365 351 on at
    RE: X++ Convert computed column in D365Fo

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

  • waytod365 Profile Picture
    waytod365 351 on at
    RE: X++ Convert computed column in D365Fo

    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
    waytod365 351 on at
    RE: X++ Convert computed column in D365Fo

    Thanks for your replay girishS,

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

  • GirishS Profile Picture
    GirishS 27,828 Super User on at
    RE: X++ Convert computed column in D365Fo

    Hi,

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

    Thanks,

    Girish S.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans