Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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.
Solved! Go to Solution.
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.
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.
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.
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.
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.
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
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.
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.
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);
Thank you, thats the very good solution.