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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to handle null value string column of a View in X++ ?

(1) ShareShare
ReportReport
Posted on by 3,175

i have created a View InventTransWithBranchDept with following records for the Item "TV":

View2.png

now here is my code, the while loop on asIsTable is just not picking the row with null or empty Department

LF_InventTransWithBranchDeptDimView grpTable;
LF_InventTransWithBranchDeptDimView asIsTable;

while select grpTable
group by grpTable.Branch , grpTable.Department, grpTable.ItemId
where grpTable.ItemId == "TV" //"10059"
{
     while select asIsTable
       where asIsTable.Branch == grpTable.Branch
         &&  asIsTable.Department == grpTable.Department
         && asIsTable.ItemId == grpTable.ItemId
              {
                  info( strFmt( "%1 - %2", asIsTable.Qty , asIsTable.Department) );
               }
}

i have tried this too but no luck  -  

(    ( asIsTable.Department == "" && grpTable.Department == "")

     ||  &&  asIsTable.Department == grpTable.Department  )

 

any help here would be appreciated

- San

*This post is locked for comments

I have the same question (0)
  • Srinath Sundaresan Profile Picture
    510 on at

    Here is how ax treats null

    msdn.microsoft.com/.../aa846236.aspx

  • San Artham Profile Picture
    3,175 on at

    Hi Srinath, thank you for the response.  I knew that null for string field is "",  in this case it is not working.

  • Verified answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    No, null for string field isn't empty string! Null is null and empty string is a non-null value. These are two completely different things. That AX (normally) doesn't use null values and always set some value is a completely different statement.

    If your view returns null values, change it to return default values instead (e.g. the default value for string fields is empty string).

  • San Artham Profile Picture
    3,175 on at

    thank you Martin, as per your suggestion i have resolved this issue by creating computed column for Department  in this pattern :

    SysComputedColumn::if(SysComputedColumn::isNullExpression(fieldName), SysComputedColumn::returnLiteral(""), fieldName);

    In SQL this would translate to:

    (CAST ((CASE WHEN T2.DEPARTMENT IS NULL THEN N'empty' ELSE T2.DEPARTMENT END) AS NVARCHAR(30))) AS MyDEPT

    For me, it should not be this complicated so this may be considered as flaw in AX X++.

    i don't think this would be the case in C#.net

    Regards,

    Santosh.

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    SQL and C# are two different things and it all depends on how the database access framework deals with null values. For example, null values in database can be translated to instances of DBNull class (which is something else then null reference...).

    Nevertheless the absence a value (= null) and an empty string souldn't ever be considered the same.

  • Pete Alberts Profile Picture
    3,542 on at

    I came across the same issue.

    I was using existing Views as examples. Do I miss understand the code, or is it a Microsoft mistake?

    Two examples: HcmPersonProjectRoleEntity::dataAreaValue() and WHSFixedProductWarehouseLocationEntity::configurationIdDefinition()

    Is it significant that the examples I mentioned are computed columns for Data Entities and not Views? I have the idea that for this purpose it is the same thing.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans