How to assign outsystem local variable with javascript?

Is it possible to assign outsystems local variable with javascript ?

Hi Reynaldleo,


As far as I know, this is not directly possible. Javascript nodes are like black boxes; you can put something in, and you can get something out.

You can define output parameters in a javascript node. After the javascript node, you can assign the output of the javascript to a local variable.

For more info visit: https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/JavaScript/Extend_Your_Mobile_App_Using_JavaScript


Regards,

Sam

Hi Reynaldleo,

Inside Javascript blocks, you can reference either actions or variables:

$parameters.MyVariable

$actions.MyAction

Regards,

Maybe you can create a hidden input bound to that local variable.

Then manipulate it using javascript:

    document.getElementById('"+HiddenInput.Id+"').value = 'xxx';

 Harlin Setiadarma wrote:

Maybe you can create a hidden input bound to that local variable.

Then manipulate it using javascript:

    document.getElementById('"+HiddenInput.Id+"').value = 'xxx';

I have written the below code in my web screen's property name JavaScript.

I have taken one input box in web screen and given the name "hiddenInput" and bound it to the variable name currentlocation.

And I am trying to display the value of currentlocation in my webscreen preparation but I am not able to see the value of currentlocation on the web screen. 



Functionality that I want to achieve:

I want to fetch the current location using below code ( this is working fine ) and want to show the marker on the map on that location.


Please help me.

Thanks


SyntaxEditor Code Snippet

 if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }

function showPosition(position) {
   var latitude = position.coords.latitude ;
   var longitude = position.coords.longitude;
   latlong = latitude +" , "+ longitude;
   document.getElementById('"+hiddenInput.id+"').value = latlong;
}



You can look in Forge my component named Google Maps Overlay. 

Inside there's Overlay Sample module. 

Using javascript there's 4 markers that can be dragged and updated lat long to a visible input on webscreen.

It works, just check my codes. 

Harlin Setiadarma wrote:

You can look in Forge my component named Google Maps Overlay. 

Inside there's Overlay Sample module. 

Using javascript there's 4 markers that can be dragged and updated lat long to a visible input on webscreen.

It works, just check my codes. 

Hi Harlin, I tried to install this component but I am getting a warning message like this.

 Application cannot be safely installed in your environmentOutSystems Platform dependency analysis has detected that installing this application would impact other applications running in your environment. You may still force the installation of the application at your own risk.Google Maps Overlay is not compatible with your platform version.


Should I install this?

Just install it to your (other) personal environment (Outsystems v11) to be safe.

I also included a Try Now button, or you can just click here:

https://harlin.outsystemscloud.com/Overlay_Sample/


Here's my code snippet:

Harlin Setiadarma wrote:

Just install it to your (other) personal environment (Outsystems v11) to be safe.

I also included a Try Now button, or you can just click here:

https://harlin.outsystemscloud.com/Overlay_Sample/


Here's my code snippet:

Hi Harlin, I am doing the same thing but still, I am not able to pass this value to my input box variable.

 Here I am able to see the value of lat longs in the alert but I am not able to get this value in the local variable in outsystems.

SyntaxEditor Code Snippet

 function showLatlong(){
 if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
function showPosition(position) {
   var latitude = position.coords.latitude ;
   var longitude = position.coords.longitude;
   latlongs = latitude +" , "+ longitude;
   alert(latlongs); // Here i am able to see the value of latlongs.
   document.getElementById('"+hiddenInput.Id+"').value = latlongs;

      
}


Marco Arede wrote:

Hi Reynaldleo,

Inside Javascript blocks, you can reference either actions or variables:

$parameters.MyVariable

$actions.MyAction

Regards,

Hi Marco Arede,

can you guide me on this


Manikandan K wrote:

Marco Arede wrote:

Hi Reynaldleo,

Inside Javascript blocks, you can reference either actions or variables:

$parameters.MyVariable

$actions.MyAction

Regards,

Hi Marco Arede,

can you guide me on this



You can have input and output parameters in JavaScript flow elements. You can also declare and use JavaScript variables inside this element as you like by writing code for it, but their scope will be limited to the element.

Assuming that in your case you're trying to set the local variable of the screen in the from the UploadOCR client action, I would do the following:

1. Define an output parameter in the JavaScript2 element (by right-clicking the "Parameters" tree node) and then set its value using something similar to the following JavaScript code:

$parameters.MyOutputParameter = 'example value';



2. In the UploadOCR action flow, add an Assign element after the JavaScript2 element and use it to assign the value of JavaScript2.MyOutputParameter to the local variable of the screen. 


Since the client action is in the scope of the screen, it has access to its local variables, even if this local variable not immediately assignable from inside a JavaScript element.