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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

"Executing a service by passing name of the service as a parameter

amittal1
9-Granite

"Executing a service by passing name of the service as a parameter

HI,

In Thingworx is there a way by which I can execute a service, through passing the name of the service as parameter from another service?

To be more clear, consider the following snippet --

 

I have two services in a thing 'Thing_Example' as 'srvA' and 'srvB'

Defination of 'srvA' --
Inputs: serviceName; Type: String; Value: 'srvB'
Service body --

var result = Things["Thing_Example"][serviceName];  //At this point I am expecting that 
                                                   'srvB' should be executed

 

Thanks and Regards

Aditya Mittal

1 ACCEPTED SOLUTION

Accepted Solutions
Ashritha
13-Aquamarine
(To:amittal1)

Use following code snippet to call service dynamically

var serviceName = "test1";
result=Things[thingName][serviceName]();

View solution in original post

9 REPLIES 9
anarwal
12-Amethyst
(To:amittal1)

Hi @amittal1 , You can call another service result on the same service . what difficulty you are facing?

Hi,

I understand that the output of one service can be called on another one.

But my requirement is different. We can call a service only if we know the name of the service. But in my case the name of the service is coming as a parameter. If you see my requirement in snippet that I provided, you will understand.

Please let me know if something is not clear.

Thanks

Aditya

anarwal
12-Amethyst
(To:amittal1)

@amittal1 , It will not be possible because Things["ThingName"].var where var is an argument will not be understood.

Ok..I thought so !!!

but for properties it is possible to have similar mechanism like--

 

var propname = prop1;

result = Things['ThingName'].prop1;  //OPTION 1; if you know the name of property

result = Things['ThingName'][propname];  //OPTION 2; If property name is coming via 
                                           service parameter

 

I thought maybe there is some way or 'trick' by which I can achieve my requirement.

 

Ashritha
13-Aquamarine
(To:amittal1)

Hi,

Make use of ContentLoaderFunctions and change the name of the service in the input url . 

slangley
23-Emerald II
(To:amittal1)

Hi @amittal1.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Hi,

I was still waiting for some comments after my last post, where I mentioned that for properties there is a way you can access them using a parametrized way. I was hoping there would be some way of executing services also.

-Aditya

Ashritha
13-Aquamarine
(To:amittal1)

Use following code snippet to call service dynamically

var serviceName = "test1";
result=Things[thingName][serviceName]();

slangley
23-Emerald II
(To:slangley)

Hi @amittal1.

 

Do you have further questions on this post?  If not, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Top Tags