cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Set session parameter from javascript

sclement1
12-Amethyst

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

ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

9 REPLIES 9
jdass
13-Aquamarine
(To:sclement1)

sclement1
12-Amethyst
(To:jdass)

Janet,

  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.

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);

    }

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.

Is that supposed to be TW.Runtime.Workspace.Mashups.Current.setParameter(<mashup parameter name>,<value>); ?

Are there any links to documentation for this and other calls in Thingworx, I can't find any good documentation.

When I try to use this, it doesn't seem to work.  It should be useable in an expression widget correct?

Thanks.

Hi Rus,

Can you provide a few screenshots and a little more detail

Hello,

I need it for other applications, but to test it I made a test mashup and put a textbox widget, expression widget, and value display widget in.

The expression widget takes an input parameter called "test" and the expression is "TW.Runtime.Workspace.Mashups.Current.setParameter(mashparam,test)". The "test" input is bound to the textbox.

I made a mashup parameter called "mashparam" and bound that value to the value display widget.

So whatever I enter in the textbox should cause the expression widget to update the mashup parameter, which should then display in the value display widget. Nothing seems to work.

Thanks that helps -  I set the same scenario up and it works. But the parameter name  mashup should be in quotes as it not really a variable

TW.Runtime.Workspace.Mashups.Current.setParameter("mashparam",test) and after press enter or tab

Ah, I forgot the quotes. Thank you! That is exactly what I needed!

Announcements


Top Tags