9 Replies Latest reply on Dec 27, 2017 1:49 PM by rrosenlof RSS
    sclement Explorer

    Set session parameter from javascript

    Does anyone know how to set a Session Parameter using javascript?  I would like to create a custom widget that sets a session parameter.  I assume I have to access the User Management Subsystem but I'm not sure how to do that in javascript.


    Thank you

        • Re: Set session parameter from javascript
          sclement Explorer


            Thank you for the suggestion.  It got me thinking down the right path.  The document describes how to create a Session Parameter but I needed to give that Session Parameter a value at runtime without binding to it.  Instead of using a Session Parameter I ended up using a Mashup Parameter which probably works out better.


            I created a "smartShape" widget that allows you to send value to a Mashup Parameter when you mouse over the widget.  I used the TW.RunTime.WorkSPace.Mashups.Current.setParameter function to set the Mashup Parameter to a value specified in the smartShape widget's properties.  The purpose is to allow me to create a Mashup that can react appropriately when an area of the screen is clicked without having to bring in the same instance of a service multiple times.  For my current purposes the smartShapes are mostly transparent but when you click on one the color changes to red to indicate that section of the screen has been clicked.  They all call the same instance of a service when clicked.  The service uses the value in the Mashup Parameter to determine which shape was clicked.

        • Re: Set session parameter from javascript
          stevegr Creator

          Try this



             var myValue = inComingValue ;


              try {

                  var params = {

                      name: "mySessionBoolean" /* STRING and must exist as a Session defined property */,

                      value: myValue  /* BOOLEAN */


                  Resources["CurrentSessionInfo"].SetGlobalSessionBooleanValue(params); // Use SetGlobalSessionXXXX based on your type

                  logger.debug(me.name+" Set Session: set mySessionBoolean to " + myValue );


              } catch(err) {

                  logger.error(me.name+" Set Session mySessionBoolean : Unable to set session mySessionBoolean Error: " + err);


            • Re: Set session parameter from javascript
              sclement Explorer

              Thank you for the response.


              The problem I have is that at runtime the javascript cannot see the Resources[] object.  So any call to it returns an error.  What you can do however is:


              TW.Runtime.Session.SetSessionValue(<session parameter>,<value>);


              However for my purposes I think using a Mashup Parameter is easier to implement.  To set the value of a mashup parameter on the current mashup:



              TW.Runtime.Workspace.Mashups.Current.setParameter(<mashup parameter name>,<);


              The custom widget I created is based off the shape widget and sets the Mashup Parameter value specified in it's properties to the value specified in it's properties.