33
Views
5
Comments
Ease of use of types
Question

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

2026-03-12 10-32-06
Wahaj Adil

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 integer
Output: decimal

this would work as a generic function and can be used across contexts.


hope this helps,
thanks and regards!

UserImage.jpg
test test

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

2025-07-22 10-30-27
Mandar Deshpande

Hi @test test 

You can use a Wrapper structure, this would be closest to using generics:

  • One input type
  • One function
  • Internal logic picks correct field
  • Caller does not need two separate functions
2023-10-16 05-50-48
Shingo Lam

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?

2023-12-26 10-35-28
OutSystems Neo
Staff
AI Generated

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:

  1. 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.

    • Decimal List Sum: Loop through the list of Decimals in a For Each and keep a running total.
    • Integer List Sum: Apply similar logic but for Integer lists. Definition and implementation would have independent parameters.
  2. Dynamic Typing Simulation:

    • You can create an action that accepts a List of Text values and within the action use the TextToInteger() or TextToDecimal() functions to parse the values dynamically for summing. However, this is not ideal if the context requires strict type handling List of calculations.
  3. Polymorphic Approach via Mapping Entities:

    • Introduce an entity with fields capturing type and value (for example: ValueType and Value). Then create logic to sum values based on the ValueType. While this has limitations, it mimics polymorphism within OutSystems Polymorphism in OutSystems.
  4. Handle Type Dynamism Using Composition:

    • If you aim to work with a mixed list (Integers + Decimals), you can convert all Integers to Decimals and reuse one logic. Perform type validation initially, then convert and follow unique summing logic.

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.

This answer was AI-generated. Please read it carefully and use the forums for clarifications
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.