Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to Replace Zero with Null in Computed Column of Views

Posted on by 135

Hi there,

             I am having a View which consist of some column and One Computed Column which returns the Addition of two Column

Eg:-  View Field1, Field2, Computed Field(Field1 + Field2)

   

             Field2 is having some Null values, so my Computed Column is returning Null for all the rows having

Field2 = Null.

In SQL we have

                          IsNull(Field2,0)

I want to achieve something like this in my Computed Column method.

I am using the Below Code for adding two fields i.e

return SysComputedColumn::add(

SysComputedColumn::returnField(
tableStr(ViewName),
identifierStr(datasourcename),
fieldStr(Tablename, Field1)),
      SysComputedColumn::returnField(
      tableStr(ViewName),
      identifierStr(datasourcename),
      fieldStr(Tablename, Field2)));

Can you please guide me how to achieve my above requirement.

Thank

Regards.

*This post is locked for comments

  • Suggested answer
    mnaeembaigAX Profile Picture
    mnaeembaigAX 80 on at
    RE: How to Replace Zero with Null in Computed Column of Views

    the complete code is

    private static server str onHand()

       {

           #define.ViewName(HUBRMConsumptionDeatilU1)

           #define.DataSourceName("InventSum_1")

           #define.FieldPostedQty("PostedQty")

           #define.FieldReceived("Received")

           #define.FieldDeducted("Deducted")

           str sReturn,

               sPostedQty,

               sReceived,

               sDeducted;

           DictView dictView2;

           dictView2 = new DictView(tableNum(#ViewName));

           sPostedQty = dictView2.computedColumnString

               (#DataSourceName,

               #FieldPostedQty,

               FieldNameGenerationMode::FieldList,

               true);

           sReceived = dictView2.computedColumnString

               (#DataSourceName,

               #FieldReceived,

               FieldNameGenerationMode::FieldList,

               true);

           sDeducted = dictView2.computedColumnString

               (#DataSourceName,

               #FieldDeducted,

               FieldNameGenerationMode::FieldList,

               true);

          sReturn = "isNull("+sPostedQty+",0) + isNull("+sReceived+",0) - isNull("+sDeducted+",0)";

           return sReturn;

       }

  • Suggested answer
    mnaeembaigAX Profile Picture
    mnaeembaigAX 80 on at
    RE: How to Replace Zero with Null in Computed Column of Views

    you can use isNull function as follows in your method;

    sReturn = "isNull("+sPostedQty+",0) + isNull("+sReceived+",0) - isNull("+sDeducted+",0)";

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans