495
Views
14
Comments
How can we write javascript in server action for reactive application?
Application Type
Reactive

Hi,

I want to write javascript code in server action. I have to call this server action in an exposed API. This requirement is for Reactive Application.

We can write javascript in client action but is there any way we can write javascript in Server action? 

Please suggest any solution that would be helpful.

Thanks!

2025-02-10 17-24-13
Arun Rajput

Hi,

You can use 'RunJavascript' server action which you can find inside HTTPRequestHandler module.

Thanks

Arun

UserImage.jpg
Ibtesam Shaikh

I assume this can't be used in Reactive, this is for traditional web application.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Ibtesam,

Why do you want to write Javascript in a server action?

Regards,

Daniel

UserImage.jpg
Ibtesam Shaikh

I am generating a pdf from dynamic template in which there are values which will dynamically be changed.

First, I was taking input values from UI using input fields, but now the requirement has changed and values need to come from API.

My template rendering code is using Mustache JS which is in client action that can't be used in API now, so I wanted to write it in server action.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

But are you expecting the JavaScript code to run server side?

UserImage.jpg
Ibtesam Shaikh

because I want to use it in an exposed API.

2025-01-09 14-56-57
IQ78

hi, 

Javascript is a client side code.

You cannot use it in the server action.

Try another approach:

1. call the API

2. send the value in Database

3. call JS and fetch that value

regards

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP


Sorry I fail to understand how that could ever work... if you want your response to by dynamic, you generate that response server side with either OutSystems lowcode or a C# extension, prior to sending the content as part of the body of your request.

2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi, on the forge you will find a custom code extension for Handlebars https://www.outsystems.com/forge/component-overview/980/handlebars-net-o11. This is based on the C# implementation of HandlebarsJS which in turn is a great templating library.

Best

Stefan

2019-03-12 09-44-05
Rodrigo Silva

I've seen MustacheJS is a node package manager(npm). So, you can try to convert it into a client library using Browserify, so that you could run any function from client action. 

https://browserify.org/#install

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Ibtesam,

I think you misunderstand the way the Platform works technically. Server-side, the Platform runs on the Microsoft .NET platform, more specifically it runs compiled C# code on Microsoft IIS (Internet Information Services). The preferred way to create server-side code is to write it in Service Studio using the visual OutSystems language, or you can create so-called Extensions, which are libraries coded directly in C#. This explicitly means it is not possible to run JavaScript, or any other type of code (PHP, Python, etc.) server-side, unless you expose it via a C# extension.

Client-side, the Platform uses JavaScript, both in Reactive and Traditional web apps, though in Traditional Web Apps mainly for widgets - all program logic runs server-side.

Running JavaScript server-side is theoretically possible, but you'd need something like Node.js to run it. The OutSystems Platform does not support Node.js, so unless you hava an on-premise infrastructure, you cannot run JavaScript. If you do have an on-premise infrastructure, you could run Node.js on a server, and e.g. call REST methods you've created and exposed in the server-side JavaScript, but this falls fully outside the scope of OutSystems or this forum, so you're on your own there.

tl;dr Combining the Outsystems code with server-side JavaScript is possible, but only in limited cases, and it is not supported. You're way better off using OutSystems-native code.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.