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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

use of GetServiceDefinitions for uncategorized services

DJ_9605282
4-Participant

use of GetServiceDefinitions for uncategorized services

Hello,

with the service:

 

result = Things[thingName].GetServiceDefinitions({

    category: category /* STRING */, ,

    type: undefined /* BASETYPENAME */, ,

    dataShape: undefined /* DATASHAPENAME */

});

 

i can get all servicedefinitons of services of a special category.
But which Sting do I need to use if i want to get all uncategoriezed services?

I've tried *Uncategoriezed*", "'Uncategoriezed*", "**Uncategoriezed**", " ", "", "uncategoriezed", "*uncategoriezed*", "**uncategoriezed**", nothing.

All of them are wrong.

Does anyone have any idea what the right string is?

 

We use thingworx 9.1.8 and 9.3.7.

ACCEPTED SOLUTION

Accepted Solutions

Assuming you know all the existing categories, here's what you can do: Query all services and subtract all the services returned by querying for all the categories. What's left over are the services without category. Not super-efficient, but it could work - under the assumption.

View solution in original post

14 REPLIES 14

Hi @DJ_9605282 

 

Try to use this: 

let result = Things['Thing'].GetServiceDefinitions({
category: undefined /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */

});

where category is undefined, you should get all services that do not have a category. 

Regards.

DJ_9605282
4-Participant
(To:Janicen)

Thanks for your reply,
Unfortunately, I tried this and as a result I get all the services, with or without a category.

 

 

What if you keep call like this, but then sort result by category == null / undefined? Maybe this is not direct method, but hope it will work?

You can't filter on that. Either you give it a non-empty string, then it filters for that string (ignoring case), or you give it undefined or an empty string, then the filter is not considered.

ZbigniewK
12-Amethyst
(To:Rocko)

Is that infotable? Then you could create a new infotable, let's called it resultTable.
Let's rename your result to tempInfotable. Let's make our own sorting procedure.
Hope it will works, if not - that's my only idea. 

let tempInfotable = Things['Thing'].GetServiceDefinitions({ 

category: undefined /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */

});

let  resultTable= Resources["InfoTableFunctions"].CreateInfoTable();
let newEntry = new Object ();
For each (row in tempInfotable.rows) {

       if (row.category == null || row.category == undefined || row.category = "") {

                 newObject = row;

                 resultInfotable.AddRow(newObject);   // I think you could also use directly resultInfotable.AddRow(row); 

        }

}

This will not work as GetServiceDefinitions will not have the category column in its output.

DJ_9605282
4-Participant
(To:Rocko)

Yes, this is the problem and there is no way to get the category of a service. For parameters, I can find the categories and have used the two ways that ZbigniewK suggested. Unfortunately, this doesn't work for service.

@DJ_9605282 ,

 

This is technically not the "correct" way to do it, but you can set up a database Thing that is connected to your Thingworx database and query the servicedefinitions table.  Then you'll be able to query by category (just an empty string).  You'll have to join it with a couple of tables (thing_model and entities_servicedefinitions I think) to actually get the services for the Thing you want.  Might be easier just to give all your uncategorized services a category though.

 

- Nick

DJ_9605282
4-Participant
(To:nmilleson)

Yes, this is a possible solution.

Unfortunately, we have a large number of Thingworx servers and each has its own database, partly MS-SQL, partly PostgreSQL. We would have to adjust the connection string and the credentials for each server.

In addition, the tables are not documented, so there is no guarantee that they will not change in a subsequent version. That's too uncertain for me.

@DJ_9605282 ,

 

Sounds like your only option is to go through and categorize all your services as tedious as that may be.  

 

- Nick

Assuming you know all the existing categories, here's what you can do: Query all services and subtract all the services returned by querying for all the categories. What's left over are the services without category. Not super-efficient, but it could work - under the assumption.

DJ_9605282
4-Participant
(To:Rocko)

Yes, that's exactly how I did it. Unfortunately, I can only filter out the standard categories, because the creative developers come up with countless and always new categories. And since we have hundreds of things and new ones are added every day, I can't possibly find them all.

Here's a slightly more elegant solution giving you an array of uncategorized services defined on the current thing:

 

let entityDef = Resources["EntityServices"].ReadEntityDefinitionAsJSON({name:"YourThingName", type:"Things"});
let sDefs=entityDef.effectiveShape.serviceDefinitions;
let services=Object.keys(sDefs).filter(s=> !sDefs[s].category && !sDefs[s].sourceName);
DJ_9605282
4-Participant
(To:Rocko)

Thank you, thats the very good solution.

Announcements


Top Tags