Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Computed column switch statement

(0) ShareShare
ReportReport
Posted on by
Hello,
I have the following scenario in x++ that I need to implement in the SalesOrderHeaderV2 entity as a computed column:

switch (SalesTable.SalesStatus)
{
    case SalesStatus::Backorder:
    if (SalesTable.DocumentStatus == DocumentStatus::None ||
        SalesTable.DocumentStatus == DocumentStatus::Confirmation)
    {
        return 'Value1';
    }
    break;
    case SalesStatus::Delivered:
    case SalesStatus::Invoiced:
        return 'Value2';
    break;
}
//return empty string if conditions are false
return '';
 
I am not too familiar with the SysComputedColumn.
Can anyone please share how this could be converted as a computed field logic?
  • Jason0810M Profile Picture
    Jason0810M on at
    Computed column switch statement
    Hello Martin,
    Actually for the BackOrder case there is another check and another value to be implement like this:
     case SalesStatus::Backorder:
        if (SalesTable.DocumentStatus == DocumentStatus::None ||
            SalesTable.DocumentStatus == DocumentStatus::Confirmation)
        {
            return 'Value1';
        } else if (SalesTable.DocumentStatus == DocumentStatus::PackingSlip||
            SalesTable.DocumentStatus == DocumentStatus::Invoice)
        {
            return 'Value3';
        }
     
    I have managed to do a switch on the SalesStatus. I have then for the Map condition of the BackOrder I have called another switch for the DocumentStatus field.
    Thanks.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,466 Most Valuable Professional on at
    Computed column switch statement
    You can utilize SysComputedColumn::switch() or SysComputedColumn::switchOrdered().
     
    Although you can use it without understanding what it does, a good first step is thinking about what T-SQL code you want to generate and only then writing X++ generating this T-SQL. Knowing what T-SQL code you want would help you finding right helper methods, at will help you if when verifying that correct code is being generated.
     
    By the way, the logic in the Backorder case makes no sense to me. The value is Backorder there, therefore there is no point in checking whether it's None or Confirmation.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans