cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the value of sy-uname global vairable from BSP (html) code?

0 Kudos

I am building a simple BSP that builds a link. The link requires the global user Id of the person running thee BSP...(sy-uname). I need to include their user name in the link. Below is my code and I want to replace the code that says "var str='TNSUSER01" with the actual sy-uname value. How do I retrieve an ABAP global variable from this BSP (HTML) code?

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var str1= '?name=' ;
var str2="TNSUSER01";
var str3="$loginstatus=0"
var url="https://eba.quinteldemo.com/eba.net/default.aspx?params=user=";

var newurl=url+str1+str2+str3;
window.location.href(newurl);

</script>
</body>
</html>

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Hi Sandra,

Thanks for your response. I checked and "without script" in the BSP properties is not checked. The page type is set to "Page with Flow Logic".

Do you happen to know if the line of code below is correct when referencing a Page Attribute value? that part of the code is in the

<script> section of the HTML:

var str2 = "<%= username %>";

0 Kudos

Thanks for the reply. So I tried the statement :

var str2 = "<%= sy-uname %>"

The result was the value of var being the literal value <%= sy-uname %>

I also tried the statement

var str2 = "<%= username %>"

Username is a global variable that I setup under "page attributes" and flagged it as "auto". In the Event Handler tab under the event "on create" I added the following code:

USERNAME = SY-UNAME.

When I use this statement in the HTML code

var str2 = "<%= username %>"

the value that is put in var is the literal <%= username %>

I am at a complete loss at this point. I feel like I tried everything. I assume if you write logic in ABAP on the Event Handler page you should be able to pass any Page Attribute variable values to the HTML page??? Here is my new code:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>


var str1= "?name=" ;
var str3= "zzzz";
var str2 = "<%= username %>";
var url="http://google.com/";
var newurl=url+str1+str2+str3;
window.location.href(newurl);

</script>
<!-- <p>The value you entered on the previous screen is: <%= username%>
</p> -->
</body>
</html>

Sandra_Rossi
Active Contributor
0 Kudos

There's a checkbox "without script" in the BSP properties. It should NOT be checked if you want ABAP code to be interpreted.

0 Kudos

.. further on from your code, if the HTML is within the BSP, you should be able to call

var str2 = "<%= sy-uname %>" and then continue as usual.

0 Kudos

Within a BSP, you can call ABAP code within the <%= and %> brackets. Thus you can try calling the sy-uname value either as

<%= sy-uname %> or by first moving it to a JS variable.