Showing results for 
Search instead for 
Did you mean: 

Cookie parameters in .xsjs

Former Member
0 Kudos

Hi all

In my .xsjs file in a SAP HANA XS application, I want to create a cookie and send it to the browser. According to the SAP HANA XS JavaScript Reference, cookies are represented as name-value pairs (they are elements of a TupelList object).

The command

$.response.cookies.set('myCookieName', 'myCookieValue');

creates a cookie with the given name/value and sets the parameters 'host', 'path' and 'expires' automatically.

My question is: How can I modify e.g. the parameters 'path' and 'expires' ? Is it possible to do it in the .xsjs ?



View Entire Topic
Former Member
0 Kudos

Hi Christopher,

If I am understanding your question right, here is your answer.

$.session.getUsername() will directly give you the username from the cookie.

You can then set it as response body and send it back.

If you need something else plz reply back.


Shubham Agrawal

0 Kudos

Hello Shubham,

  Can you tell me how I can set the cookies in the request header.How can I set the tupple list


Developer Advocate
Developer Advocate
0 Kudos

You mean for outbound HTTP Connectivity from XSJS?  Its not really any different than setting them on the response.  Here is an example:

  var rfcRequest = new $.web.WebRequest($.net.http.POST, endpoint );

rfcRequest.cookies.set(sessionId, sap_session );
0 Kudos

Hi Thomas,

For a vanilla HTTP call to an XSJS endpoint, I could not find a viable way to send back an HTTP cookie with cookie properties such as "HTTP-Only", "Path" or "Expires" set.

The following code does NOT set these properties as expected:

$.response.cookies.set('cookiename', "value;expires=" + new Date().toJSON().toString() + ";;path=/;");

but instead, sets the value of the "cookiename" cookie to the entire string.

It would be a big help to actually be able to set these cookie properties in a normal HTTP call. Is there any other way to achieve this?



Former Member
0 Kudos

Hi Shubham,

I need something other than the username. Do you have any idea how to do that properly?

I want to set some information related to the current session to the cookies, because I don't see any method in $.session that allows me to do that. But the problem comes to how to unset them (before the session end/logout)? I don't find any way to do this, and the JSDoc for XSJS has very little information on this.

Thanks in advance.