Saving JavaScript function/object/class as an OutSystems Local Variable?

Hello,

I'm trying to implement a client-side hashmap for Reactive using JavaScript. I have a mostly working implementation at this point; the only caveat is that the JS variable that holds said hashmap is defined in global scope (and so, accessible via the browser's console), which is a problem because I don't want the end-user to directly manipulate the hashmap in any way.

So I thought if my Init Client Action outputs an instance of my Hashmap pseudo-class (which could be a JS function or Object) I could then assign it to an OutSystems Local Variable and pass it around as needed, while keeping it "hidden" from global scope.

Is this approach possible? If so, how? And if not, is there another approach that would lead to the intended result?

Platform Version: 11.8.0 (Build 12006)
Service Studio Version: 11.8.1 (Build 24074)
Stack: Reactive Web

Thanks in advance,
Tiago Veloso

Solution

Hi Tiago,

I think you can store the Object value in the OutSystems Local Variable i.e 

1) Introduce an Local variable of data type as Object type 

2) In the JS node introduce an Output parameter which is of Object data type

3) Set the Object value from the JS node output parameter to the Local Object type variable using the assign node.

By this you can pass the Object type Local Variable value around as needed, while keeping it "hidden" from the global scope.


Hope this helps you!

Regards,

Benjith Sam

Solution

Hi Benjith,

This worked wonderful, thanks! I thought it would be much harder once some of my Object's values were functions, but it seems I was wrong.

By the way, could the same effect be achieved with just JavaScript? As in, defining a variable somewhere within a Script and have access to it from JavaScript nodes, but not from the console?

Tiago Veloso wrote:

Hi Benjith,

This worked wonderful, thanks! I thought it would be much harder once some of my Object's values were functions, but it seems I was wrong.

By the way, could the same effect be achieved with just JavaScript? As in, defining a variable somewhere within a Script and have access to it from JavaScript nodes, but not from the console?

You are welcome, Tiago... glad that it helped you :)

Note: The below mentioned statement is based on my experience and knowledge level, I may be wrong in this!

I don't think that we do have any other way to declare the global variable, of which the value can't be accessed from the browser console. 


Regards,

Benjith Sam