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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

State based formatting for Image widget

ptc-6291975
1-Visitor

State based formatting for Image widget

Hi,

 

I am trying to make the image widget to display the icon image based on the state. For other widget such as Google Map, this can be done easily using the State Based Formatting. However, it seems I couldn't find such feature for Image widget.

 

Was trying to use scripting way to achieve it as below.

 

var result; 

 

if(Things[Station_ID].RemoteMachineConnected == true)

    result = MediaEntities["Connection_Up"].GetImage();

 

else {

result = MediaEntities["Connection_Down"].GetImage();

}

 

However, the resulting Image couldn't be linked in Mashup as Image widget is expecting Source URL.

 

How do we get the URL of a media entity through script? Or if there is built-in State-based formatting in Image widget?

 

Thanks in advance!

4 REPLIES 4

Hi Yew,

By using the Value Display as opposed to the Image widget, your Mashup will be able to support the Service you've already written. If you prefer to use the Image widget, your Service simply needs to return an IMAGELINK of the following format: "Thingworx/MediaEntities/name_of_Media_Entity".


Thanks,

Adam



Thanks Adam.

For the value display suggestion. It works.


For the Image widget suggestion, 

I tried using var result = MediaEntities["Connection_Down"];  with result set to IMAGELINK. But seems it returned a broken link. Just wanted to find out more if the script is written correctly in this case...


Using REST way Thingworx/MediaEntities/Connection_Down renders the image successfully though.


Please advise. Thanks!



Yew,

To use the Image widget, you would set result to:


result = "Thingworx/MediaEntities/Connection_Down";


and have your Service return an IMAGELINK. You can then bind the result from your Service to the Image widget's SourceURL property.</div></p>

jlittle
12-Amethyst
(To:adam11)

Just a clarification point here, as I got stuck for a few moments on Thingworx 6.5 using the strings suggested above.

The result string needs a leading slash:

  result = "/Thingworx/MediaEntities/Connection_Down";

Omitting the leading slash resulted in a broken image for me.

Announcements


Top Tags