Hi. I am using C# decimal functions such as Math.Abs, Math.Round, etc. in a method on a page edit module, but it is not accepted. why is that?
Like
Dear Ricardo,
In order to use the static “Math” class in C# code you should add the “System” namespace to the file:
using System;
If the issue still exists, please provide us with a source code of the module and the error message. It will help us to analyze the issue in more details.
Additionally, please find more information about the “Math” class in the article by the link below:
https://docs.microsoft.com/en-us/dotnet/api/system.math?view=netcore-3.1
Best regards,
Norton
Norton Lingard,
Thanks for your prompt reply.
the code follows.
Where exactly in the code should I insert "using System; " ?
+++++++++++++++++++++++
define("FinJournal1Page", [], function() {
return {
entitySchemaName: "FinJournal",
attributes: {
"FinJrnNetAmount": {
dataValueType: Terrasoft.DataValueType.FLOAT,
dependencies: [
{
columns: ["FinJrnAmount"],
methodName: "calculateNetValue"
}
]
}
},
modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
details: /**SCHEMA_DETAILS*/{
...
}/**SCHEMA_DETAILS*/,
businessRules: /**SCHEMA_BUSINESS_RULES*/{
...
}/**SCHEMA_BUSINESS_RULES*/,
methods: {
onEntityInitialized: function() {
// Method parent implementation is called.
this.callParent(arguments);
this.calculateNetValue();
},
calculateNetValue: function() {
//
// MATH USE EXAMPLE
//
var amount = this.get("FinJrnAmount");
if (!amount) {
amount = 0;
}
var absAmount = Math.Abs(amount) ;
result = Math.Round(absAmount * 0.015, 2);
this.set("FinJrnNetAmount", result);
}
},
dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
diff: /**SCHEMA_DIFF*/[
...
]/**SCHEMA_DIFF*/
};
});
+++++++++++++++++++++++
Best Regards,
Dear Ricardo,
It is impossible to use C# code inside JS code. Please note that it exists similar “Math” object in JS language. Please find more information about it in the article by the link below:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
Best regards,
Norton