Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / How to convert null va...
Finance forum
Suggested answer

How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

Posted on by Microsoft Employee

Hi Folks.

I had a requirement for a custom lookup of ItemId on sales Line for External ItemId to be included. I have duplicated the standard Query and the View for the same and have added the CustVendExternalItem table with Outer Join.

 [FormControlEventHandler(formControlStr(SalesTable, SalesLine_ItemId), FormControlEventType::Lookup)]
    public static void SalesLine_ItemId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysTableLookup       sysTableLookup  = SysTableLookup::newParameters(tableNum(ALE_InventItemIdLookupSimpleView), sender);
        Query                query           = new Query();
        QueryBuildDataSource qbds;
        //CustAccount          custAccount = sender.formRun().design().controlName(formControlStr(SalesTable, CustAccount)).valueStr();
        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        
        qbds            = query.addDataSource(tableNum(ALE_InventItemIdLookupSimpleView));
        //qbds.addRange(fieldNum(ALE_InventItemIdLookupSimpleView , CustVendRelation)).value(strFmt('%1',SysQuery::valueNotEmptyString()));
        // Add fields
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, ItemId));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, Product));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, ProductName));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, NameAlias));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, ExternalItemId));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, ItemGroupId));
        sysTableLookup.addLookupfield(fieldNum(ALE_InventItemIdLookupSimpleView, ItemType));

        // Run lookup
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();               

        //cancel super() to prevent error.
        ce.CancelSuperCall();
    }

In the View on the table browser "" was not working and when i have checked in the DB so it has shown in Null value 
to over come I have used in DB ISNULL(FieldName,"") and it worked. I want to do the same in D365 fo. I have gone through many of the blogs and found SysComputedColumn class. I am not aware how to use it.

SysComputedColumn::if(SysComputedColumn::isNullExpression(fieldName), SysComputedColumn::returnLiteral(""), fieldName);
 
https://robscode.onl/d365-outer-join-in-view-with-null-enum-column/

Kindly help me out on this issue.

would be appreciated.

Cheers.

  • Martin Dráb Profile Picture
    Martin Dráb 228,358 Most Valuable Professional on at
    RE: How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

    If you have no idea about how to create computed columns, your should fix that by reading an article on this topic. For example: Computed View Columns in AX 2012.

    Then you should be able to utilize what I gave you above.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

    I have no idea of the syntax or using the SysComputedColumn Class in x++/view.

    I am simply asking to help me achieve to replace null value like below 

    You can see the Null value is coming in CusvendRelation and ExternalIntemId

    To this as below with null value be replaced by " " blank
    you can see using ISNULL the same wants in x++

    Or you can share anything that can help me to get rid of this null value to blank. 

  • Martin Dráb Profile Picture
    Martin Dráb 228,358 Most Valuable Professional on at
    RE: How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

    I'm sorry, but it's not clear to me what kind of advise you want about my code. What problem do you have with it?

    Regaring fieldName, the thread you've linked doesn't seem to contain its definition - neither from me nor anybody else. Couldn't you please simply show your actual code? Just a hint - you should get the value by something like SysComputedColumn::returnField().

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

    return strFmt('ISNULL(%1, \'\')', fieldName);

    Hi Martin,

    Thanks for the reply.

    Could you please advise as you have mentioned above code?

    As per you query for field name I have picked it from on of your replied Link below
    https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/161366/how-to-handle-null-value-string-column-of-a-view-in-x

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,358 Most Valuable Professional on at
    RE: How to convert null value to (" ") blank sting in a view that has been used an outer join using SysComputedColumn in d365fo?

    I would simply use ISNULL(), as you mentioned. Using if() and isNullExpression() looks overcomplicated to me in this case.

    For example:

    return strFmt('ISNULL(%1, \'\')', fieldName);

    Just note that you didn't show us how you've populated fieldName variable, therefore we can't review this part.

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,459 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,358 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans