Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
How can i go for duplicating a service of a specific thing inside other entities like things or thing templates?
I'm not sure why you need to duplicate a service.
You could just create a central helper Thing with services and then invoke that service from the other Entities.
Especially if it is doing the same evaluation.
Why not implement the shared service in a ThingShape and both entities will implement that shape?
You might also like to try:
// result: INFOTABLE dataShape: "ServiceDefinition"
var result = ThingTemplates["YouThing"].GetServiceDefinition({
name: "serviceToCopy" /* STRING */
});
//see ServiceDefinition data shape for the below paramter inputs
ThingTemplates["OtherThing"].AddServiceDefinition({
name: undefined /* STRING */,
description: undefined /* STRING */,
remoteServiceName: undefined /* STRING */,
category: undefined /* STRING */,
remote: undefined /* BOOLEAN */,
parameters: undefined /* INFOTABLE */,
resultType: undefined /* INFOTABLE */,
timeout: undefined /* INTEGER */
});
Actually, i needed a help with a default service 'AddServiceDefinition()'. With this service i'm being able to insert a service inside an entity, but being unable to insert a code in that inserted service. Can u help me on this?
I'm sorry but I'm not sure how or if it is even possible to "inject" code to a new Service.
The code can come from different places, from Jars or Composer Js and so on.
Please try the ThingShape approach and see if it can help you.
This will only work with Remote Services, ie Services on a connected Thingworx Agent
it will not allow you to create new regular defined services.
@PaiChung Actually, with the available snippet, i'm being able to insert a service in the desired entity (like Thing or Thing Template) but being unable to insert a code into that service. So, this way i'm quite sure that there could be some way for inserting a code too. Kindly help me on this.