Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Views computed columns issue

Posted on by Microsoft Employee

Hi,

I am trying to understand computed columns. I am working on an example that won't work for me. Let's say that I have a view consisting of InventTable. I want to add a computed column where I fetch the UnitId from InventTableModule.

I created a method that looks like this but the in my view the computed column is empty. What am I doing wrong?

private static server str unitId(int branchNum)

{

   #define.ViewName(CAP_Test)

   #define.DataSourceName("InventTable_1")

   #define.FieldToComputeWith("ItemId")

   str sReturn, sTemp99, sTemp98;

   DictView dictView2;

   //-------- EndOf variable declarations. ---------

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

   sTemp99 =

       "(SELECT top 1 InventTableModule.UnitId"

       + " from InventTableModule "

       + " where InventTableModule.ModuleType =  0 AND "

       + " InventTableModule.ItemId = '" ;

   stemp98 = dictView2.computedColumnString

               (

                   #DataSourceName,

                   #FieldToComputeWith,

                   FieldNameGenerationMode::WhereClause,

                   true

               );

   sReturn = sTemp99 + sTemp98 + "')";

   return sReturn;

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Views computed columns issue

    Easy one. :)

    Thx!

  • Verified answer
    Heinz Schweda Profile Picture
    Heinz Schweda 1,365 on at
    RE: Views computed columns issue

    Hi Sebastian, you have to remove the two single Quotation marks (').

    private static server str unitId(int branchNum)

    {

      #define.ViewName(CAP_Test)

      #define.DataSourceName("InventTable_1")

      #define.FieldToComputeWith("ItemId")

      str sReturn, sTemp99, sTemp98;

      DictView dictView2;

      //-------- EndOf variable declarations. ---------

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

      sTemp99 =

          "(SELECT top 1 InventTableModule.UnitId"

          + " from InventTableModule "

          + " where InventTableModule.ModuleType =  0 AND "

          + " InventTableModule.ItemId = " ;

      stemp98 = dictView2.computedColumnString

                  (

                      #DataSourceName,

                      #FieldToComputeWith,

                      FieldNameGenerationMode::WhereClause,

                      true

                  );

      sReturn = sTemp99 + sTemp98 + ")";

       print(sReturn);

      return sReturn;

    }

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans