Skip to main content
1-Visitor
December 31, 2015
Question

How to run javascript code in the composer ?

  • December 31, 2015
  • 2 replies
  • 10453 views

Hi,

I want to run a simple javascript code in the composer.

For that I added a service and tried to test it.

I tried almost all options given in the result.

But none of it worked.

What extra settings must be done inorder to work this code.

2 replies

16-Pearl
January 2, 2016

Could you provide more information. For example what kind of Thing and Service you created. What is the service doing? The script you was running and how you was testing.

pr-211-VisitorAuthor
1-Visitor
January 2, 2016

I want to split a URL  in the following format using javascript and it is to be added as a service in the Composer.

http://ge2-3506.cloud.thingworx.com/Thingworx/Things/Logistics/Properties?method=put&value=J02|T|56|32|0|4.40,SREE,DW01

The values of the properties are given after the put&value. I want to extract each value using  ' | ' as a splitter. Can you provide me with a sample code ?

I tried a simple javascript code in the service menu. But it is not working . Can you provide me with more details for the same.

16-Pearl
January 2, 2016

Parvathy,

Ok this helps but couple of questions

Is your problem running javascript or getting values into the properties?

Below is some information on getting values into a service rather than the simple put method you are using (I don't see an appKey in your example and I'm not sure how you are going to run the application)

The example may not be what you are looking for but might help you to provide additional detail around your example.

Also I'm not sure what you are trying to do inside the menu. You could add a few screen captures that would help.

This example is using a PI device and running Python to send the request you urlib import libraries to send the request and get a response (I'm not sure how you are pushing your requests)

url=  http://myhost/Thingworx/Things/MyThing/Services/MyThing_Service?appKey=ec3343-eca7-4412-9afad-fgcf9c…

post_data_dictionary = {'prop1' :JO2,  'prop2' : T,  'prop3' : 56, 'prop4':32, 'prop5' : 3.40 SREE DW01}

post_data_encoded = urllib.urlencode(post_data_dictionary)

request_object = urllib2.Request(url, post_data_encoded)

response = urllib2.urlopen(request_object)

The MyThing_Service was added to the Thing and it has a Input/Outputs script for example

me.prop1= parseString(prop1);

me.prop2= parseFloat(prop2);

me.prop3= parseFloat(prop3);

me.prop4= parseFloat(prop4);

me.prop5 = parseFloat(prop5);

logger.debug("My Service Test data");

logger.debug("prop1: "+prop1);

logger.debug("prop2: "+prop2);

logger.debug("prop3: "+prop3);

logger.debug("prop4: "+prop5);

From the MyThing you can test the MyService to check if the values can be received as expected with now error

pr-211-VisitorAuthor
1-Visitor
January 5, 2016

Hi,

This is the URL format.

http://ge2-3454.cloud.thingworx.com/Thingworx/Things/Logistics/Properties/test?method=put&value=J02|1|hello|4.40|SREE,DWO1

The pipe is a seperation used for seperating different parameters. I want to update each value in the Mashup created.

1-Visitor
January 5, 2016

Is it normal that there is "test" after "Properties/" ?

In the PDF of Steve, it's "/Properties?method=put&value="

16-Pearl
January 5, 2016

Test is not normal correct. And the approach I suggested is not actually going to run the put method it was just to show how you could generate a URL from the properties. The Logistics Thing is updated by action of pressing the button and the services it is connected to.

I have attached the Entities export. So you should be able to import - Note: the URL will need to be changed as it is set to local host which probably will not work. It needs to be the host name of the server you are connecting to.

PARVATHY R​ can you try to import the attached - It should help you understand the approach