Hi everyone,
I have a scenario involving two applications:
APP1: This application has a set of server actions.
APP2: In this application, I’ve created an entity to store server action names and other set of data.
Requirement
In APP2, I have a detail screen for a specific record with a button. On clicking this button, I want to call the specific server action. The button action should be same, but based on the name in record the specific server action should be invoked.
Question
Is it possible to dynamically call a server action based on name stored in an entity in APP2?
If yes, could you guide me how to implement it
If no, then is there any other possible way or solution to my requirement?
Thanks in advance for your help!
Hi @Gowtham ,
Out-of-the-box, you cannot dynamically call a Server Action in OutSystems based only on its name stored in an entity. APP2 still needs to reference the actions from APP1, and the calls need to be explicitly defined in the logic.
A possible approach would be to create an orchestration/dispatcher action that receives the action name as input. Inside that action, you can use a Switch to decide which referenced Server Action should be called.
There is an old article about this here: How to dynamically call an action in Outsystems, based on the eSpace name and Action name. – Knowledgebase .
And a forge component based on it: Action Reflection - Overview (O11) | OutSystems .
You could take a look at them and see how the logic is implemented and see if you can replicate it in ODC.
Thanks @Mihai Melencu for your answer. Is this approach possible through API's. Exposing actions as API in one application. Storing the API URL in an entity in another application. Based on record specific API endpoint dynamically call the API. APP1 may be exposing multiple API/methods but in APP2 in need to consume only one API, and that API should dynamically change URL and call the specific API. Is this possible? If so how can I implement it.
Hello @Gowtham
Yes, this is possible, but not by dynamically invoking OutSystems Server Actions by name. For external APIs, the recommended approach is: Store API Base URL and configuration in Entity/Site Properties. Use REST APIs with dynamic Base URL (OnBeforeRequest or Extension logic). Keep one wrapper action in APP2 to decide which API endpoint to call. Important: OutSystems Server Actions are compile-time references, so they cannot be executed dynamically from a string value. External REST endpoints can be dynamic because the URL is resolved at runtime. Best practice: Use a Strategy/Dispatcher pattern instead of trying to execute actions by name dynamically.
This adds the architectural distinction clearly:
Thanks and Regards,Akshay Deshpande
Thanks @Akshay Deshpande for you reply.
I have created attributes in the entity to store the base url and endpoint. Can you guide me on how to change the URL dynamically in on_before_request. An OML with sample would be helpful.
Thanks,
Gowtham
You can dynamically change the API Base URL at runtime based on DB values.
Example approach:
Request.BaseURL = APIConfig.BaseURL
or
Request.URL = APIConfig.BaseURL + "/customers/get"
depending on how your REST method is configured.
Switch APINameCase "CustomerAPI": CustomerAPI.GetCustomers()Case "OrderAPI": OrderAPI.GetOrders()
Important distinction:
Best practice: Keep all API routing logic centralized in one wrapper action for easier maintenance and governance.
I do not have a ready reusable OML currently, but the above pattern is the recommended in your case.Thanks and regards,Akshay Deshpande
No, OutSystems does not support invoking a Server Action dynamically by its name stored in a database or variable. Server Actions are statically bound at compile time, so you cannot execute an action simply by passing its name as a string.
A few alternative approaches you could consider:
Dispatcher/Router Pattern (Recommended)
Switch ActionName- "ActionA" -> Call ActionA- "ActionB" -> Call ActionB- "ActionC" -> Call ActionC
In most cases, the Dispatcher/Router Pattern is the simplest and most maintainable solution. It keeps all execution logic centralized while allowing APP2 to remain configuration-driven.
Thanks everyone for you replies and spending your time for my question. I have found a solution for my usecase in the following post - https://www.outsystems.com/forums/discussion/106462/calling-apis-dynamically-between-two-applications/