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!
Hi,
You can use 'RunJavascript' server action which you can find inside HTTPRequestHandler module.
Thanks
Arun
I assume this can't be used in Reactive, this is for traditional web application.
Refer the below thread
https://www.outsystems.com/forums/discussion/63892/in-action-flows-in-a-screen-action-or-a-server-action-cant-see-use-runjavascri/
Krishnanand Pathak
Hi Ibtesam,
Why do you want to write Javascript in a server action?
Regards,
Daniel
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.
But are you expecting the JavaScript code to run server side?
yes
why?
because I want to use it in an exposed API.
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
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.
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
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
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.