how to call a computed column in a method?

Question Status

Suggested Answer
Nourhan Nagib asked a question on 10 Apr 2017 6:12 AM

I've created a computed column and I want to create a new method using those computed column in dynamics AX 2012

Reply
Suggested Answer
Vilmos Kintera responded on 10 Apr 2017 6:25 AM

It is not different from any other fields, so you refer it by View.Field

Reply
Nourhan Nagib responded on 10 Apr 2017 9:43 AM

thanks for the help but it gives me an error when I write this method(public static server str GrossTons()

{

   return SysComputedColumn::add(

     /*expression_1*/  SysComputedColumn::returnField(

                       tableStr(View3.MBTon),

     /*expression_2*/  SysComputedColumn::returnField(

                       tableStr(View3.CulletTon));

}

)

Reply
Martin Dráb responded on 10 Apr 2017 10:03 AM

Of course it gives you an error if you're trying to call returnField() with just a single parameter (it requires three) and you're trying to call tableStr() with something that clearly isn't a valid table name.

Reply
Nourhan Nagib responded on 12 Apr 2017 6:24 AM

i'm sorry it is not working I tried everything and it is not working even this code

public static server str GrossTons()

{

    // declaration for the computed column// real MBTons,CulletTons;

   return syscomputedcolumn::add(MBTons,CulletTons);

}

it gives me this error: arguments is incompatible with the required type

All I want to do to have a new computed column called GrossTons by adding two computed columns which are MBTons and CulletTons

Thank you:)

Reply
Suggested Answer
Vilmos Kintera responded on 12 Apr 2017 6:44 AM

Position your cursor in front of the opening brace character (

Press Control+Shift+Space key combination, which will tell you what is the parameter that is required as an input. Then compare what you have passed in, and you should realize what you are passing in is incorrect, that is why you get the compiler error. Martin already told you this.

You can also refer to the documentation:

https://msdn.microsoft.com/en-us/library/syscomputedcolumn.add.aspx

It says the required input are SQL Expression strings, and you obviously have not sent that in for the method. Use Google search or Bing to find examples, it would give you a ton of results from fellow community members, like this one:

https://community.dynamics.com/ax/b/dynamicsaxconcoction/archive/2015/07/16/ax2012-r3-use-of-syscomputedcolumns-to-build-smart-ax-views

Reply
Suggested Answer
Vilmos Kintera responded on 10 Apr 2017 6:25 AM

It is not different from any other fields, so you refer it by View.Field

Reply
Suggested Answer
Vilmos Kintera responded on 12 Apr 2017 6:44 AM

Position your cursor in front of the opening brace character (

Press Control+Shift+Space key combination, which will tell you what is the parameter that is required as an input. Then compare what you have passed in, and you should realize what you are passing in is incorrect, that is why you get the compiler error. Martin already told you this.

You can also refer to the documentation:

https://msdn.microsoft.com/en-us/library/syscomputedcolumn.add.aspx

It says the required input are SQL Expression strings, and you obviously have not sent that in for the method. Use Google search or Bing to find examples, it would give you a ton of results from fellow community members, like this one:

https://community.dynamics.com/ax/b/dynamicsaxconcoction/archive/2015/07/16/ax2012-r3-use-of-syscomputedcolumns-to-build-smart-ax-views

Reply