Skip to main content

Notifications

Announcements

No record found.

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

View with a conditional computed column

(0) ShareShare
ReportReport
Posted on by 69
Hallo,
i have question for my case, i have logict like on my view.
 
 
but its not work, when i check on database
on all of typecomp return value delivery
 
Thanks, any input is greatly appreciated! 
 
 
  • Suggested answer
    Dodi Profile Picture
    Dodi 69 on at
    View with a conditional computed column
    Dear Layan,
     
    Thank you for helping me.
    I just changed the script code and it worked
     
        public static server str GetTypeComp()
        {
            return SysComputedColumn::if(
                    SysComputedColumn::isNotNullExpression(
                        SysComputedColumn::comparisonField(tableStr(my_view), identifierStr(SalesLine), fieldStr(SalesLine, InventTransId))
                                                           ),
                        SysComputedColumn::returnLiteral("Delivery"),
                        SysComputedColumn::if(
                            SysComputedColumn::equalExpression(
                                SysComputedColumn::comparisonField(
                                    tableStr(my_view),
                                    identifierStr(WHSLoadTable),
                                    fieldStr(WHSLoadTable, InventLocationId)
                                                                   ),
                                    SysComputedColumn::comparisonLiteral("STGCUST")
                                                                ),
                            SysComputedColumn::returnLiteral("Return"),
                            SysComputedColumn::returnLiteral("Moving")
                                            )
                                        );
     }
     
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,272 Super User 2024 Season 2 on at
    View with a conditional computed column
    Hi Dodi,

    You can't write normal x++ code. Your code needs to be translated to T-SQL. So Please try this:

    **Replace View1 with your view name "Sum_OrderManagementDeliveryView"
        public static server str getTypeComp()
        {
            return SysComputedColumn::if(
                    SysComputedColumn::isNotNullExpression(
                        SysComputedColumn::comparisonField(tableStr(View1), identifierStr(SalesLine), fieldStr(SalesLine, InventTransId))
                                                           ),
                        SysComputedColumn::returnLiteral("Delivery"),
                        SysComputedColumn::if(
                            SysComputedColumn::equalExpression(
                                SysComputedColumn::comparisonField(
                                    tableStr(View1),
                                    identifierStr(WHSLoadTable),
                                    fieldStr(WHSLoadTable, InventLocationId)
                                                                   ),
                                    SysComputedColumn::comparisonLiteral("STGCUST")
                                                                ),
                            SysComputedColumn::comparisonLiteral("Return"),
                            SysComputedColumn::comparisonLiteral("Moving")
                                            )
                                        );
    
        }
    if it doesn't work, then please go to SQL, look for your view in object explorer, then right click on it and choose design, copy the query generated and run it, if it doesn't work, then play with the query logic until it works in SQL, then translate it back to x++

    Please update us with the result.

    Thanks,
    Layan Jweihan

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,759 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans