I have a problem. I often wrap some tool methods during development, such as what I originally meant to create a client method Sum(List<Decimal | Integer>) and use it as a Function in Expression
But I found that OutSystem cannot be created like this, and the entry parameters cannot be of this type. Therefore, we need to create two client methods SumDecimal(List<Decimal>) / SumInt(List<Int>), which is not easy to use.
Is there any solution that can solve my above problem and make it easier to use, just like TypeScript
hi @test test , hope you're doing well.
If you are doing all this at a client side and want a single reusable method. You can try and write JavaScript.
Client Action -> Run JavaScript -> Output (Decimal)
function sum(list) { return list.reduce((a, b) => a + b, 0);}
Input: list of decimal integerOutput: decimal
this would work as a generic function and can be used across contexts.
hope this helps,thanks and regards!
I don't understand it very much, because my Sum function is used for summing operations. This function is used in many places, such as client logic and server logic or expression. I think "JavaScript" Logic cannot be reused
Hi @test test
You can use a Wrapper structure, this would be closest to using generics:
I think Decimal contains Int, just the sum method for Decimal is enough for both Decimal and Int data type
do I understand correctly your case?
OutSystems does not support generic methods in the same way that TypeScript does due to its strongly typed nature. However, you can achieve similar functionality by leveraging overloading and type checks. Here's how you might approach this:
Separate Actions for Decimals and Integers: Create two separate server actions, one for summing Decimal lists and one for Integer lists. Although this duplicates some logic, it aligns well with OutSystems' strong typing.
For Each
Dynamic Typing Simulation:
List of Text
TextToInteger()
TextToDecimal()
Polymorphic Approach via Mapping Entities:
ValueType
Value
Handle Type Dynamism Using Composition:
Unfortunately, OutSystems does not provide TypeScript-like generic functionality directly, but through the approaches outlined above, you can still implement a solution catering to both scenarios.
If you want to go dynamic, you could explore extending the functionalities with JavaScript and custom logic based on runtime evaluations, although this typically applies to client-side logic rather than server-side processes Polymorphism in OutSystems.
Let me know if there's a specific use case you'd like to drill down deeper into.