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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to safely remove the whole ModelTagVocabulary, all it's terms and references

tcoufal
12-Amethyst

How to safely remove the whole ModelTagVocabulary, all it's terms and references

Hi Guys,

I have rather unusual problem.

We do have a production instance version of 6.6.2.

There must have been a bug in that build, because back then it allowed me to create a ModelTagVocabulary named:

developers even though that there was already vocabulary named Developers (with different case).

Now I need to upgrade our TW version, and when I am doing export->import (via source control entities as well as with ThingWorx storage) I have an error:

Vocabulary developers already exists, but with different case. So I choose not to import that Vocabulary, but now every entity that contains that tag is not working.

Is there a safe way how to delete whole Vocabulary, all it's terms and references to those terms?

I need to clear my system before I do the export.

Thanks a lot

Tomas

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:tcoufal)

Easiest one to use would be SearchModelTags

This will return a list of Entities then step through each do RemoteTags and then AddTags or you can use SetTags which overwrites the original Tag(s)

View solution in original post

11 REPLIES 11
PaiChung
22-Sapphire I
(To:tcoufal)

In the version upgrades as you have noticed, now Thingworx treats developers and Developers as the same.

What I would recommend is to go back to the original and write a script that first finds all the entities tagged and then it removes them and adds the proper non-interfering tag.

You can use a variety of the search functions to search for tagged items.

tcoufal
12-Amethyst
(To:PaiChung)

I have never worked with search functions. Would you mind to give me a hand?

Thanks a lot for that info though.

PaiChung
22-Sapphire I
(To:tcoufal)

Easiest one to use would be SearchModelTags

This will return a list of Entities then step through each do RemoteTags and then AddTags or you can use SetTags which overwrites the original Tag(s)

tcoufal
12-Amethyst
(To:PaiChung)

Thanks, got it.

Tomas

tcoufal
12-Amethyst
(To:PaiChung)

Hi Pai,

one question though.

I have my Thing and its service made like this:

var params = {

  maxItems: undefined /* NUMBER */,

  types: undefined /* JSON */,

  aspects: undefined /* JSON */,

  excludedAspects: undefined /* JSON */,

    tags: "developers:coufalt" /* TAGS */

};

// result: INFOTABLE dataShape: "EntityDescriptor"

var myEntities = Resources["SearchFunctions"].SearchModelTags(params);

var tableLength = myEntities.rows.length;

var count = 0;

for (var x = 0; x < tableLength; x++) {

  var row = myEntities.rows;

    var myEntity = row.name;

   

    try {

        var params = {

            tags: "developers:coufalt" /* Application:Tag1  */

        };

        Things[myEntity].RemoveTags(params);

        count++;

    } catch(err) {

        logger.warn(err);

    }  

}

logger.warn("cleaned " + count + " tags");

Problem with that is that it only cleans the Things. If I want to clean Mashups I can substitute the Things[myEntity] for let say Mashups[myEntity],

unfortunately enough I tagged things like MediaEntities (dont realy know why I did that....) and things like DataShapes, ThingShapes, Users and even Oganisations. Well almost everything.

How can I reference those things? I thought that I can do it like this:

var myEntityType = row.parentType

[myEntityType][myEntity].RemoveTags(params)

but that does not work.

Any idea?

Tomas

PaiChung
22-Sapphire I
(To:tcoufal)

Right that is very unfortunate as those do not support these services.

Unfortunately my best recommendation is to clean those manually. You can find them fairly easily by using the advanced filter in composer.

tcoufal
12-Amethyst
(To:PaiChung)

Turned out, they do

I have changed script to this and it worked:

for (var x = 0; x < tableLength; x++) {

  var row = myEntities.rows;

    var myEntity = row.name;

    var myEntityType = row.parentName;

   

    try {

        var params = {

            tags: "developers:coufalt" /* Application:Tag1  */

        };

        if (myEntityType == "MediaEntities") {MediaEntities[myEntity].RemoveTags(params);}

        else if (myEntityType == "DataShapes") {DataShapes[myEntity].RemoveTags(params);}

        else if (myEntityType == "ThingShapes") {ThingShapes[myEntity].RemoveTags(params);}

        else if (myEntityType == "Users") {Users[myEntity].RemoveTags(params);}

        else if (myEntityType == "ThingTemplates") {ThingTemplates[myEntity].RemoveTags(params);}

        else if (myEntityType == "StyleDefinitions") {StyleDefinitions[myEntity].RemoveTags(params);}

        else if (myEntityType == "Organizations") {Organizations[myEntity].RemoveTags(params);}

        else if (myEntityType == "Mashups") {Mashups[myEntity].RemoveTags(params);}

        else if (myEntityType == "Menus") {Menus[myEntity].RemoveTags(params);}

        else if (myEntityType == "Groups") {Groups[myEntity].RemoveTags(params);}

        else if (myEntityType == "StateDefinitions") {StateDefinitions[myEntity].RemoveTags(params);}

        else if (myEntityType == "ApplicationKeys") {ApplicationKeys[myEntity].RemoveTags(params);}       

        count++;

    } catch(err) {

        logger.warn(err);

    }

}

PaiChung
22-Sapphire I
(To:tcoufal)

Ah even better (I think I had a utility similar to this in the past)

tcoufal
12-Amethyst
(To:PaiChung)

I call it, TagKiller

One follow up question (perhaps I will make a new thread). I am having some troubles with migration.

I have one server TW 6.6 and I want to move it to the new server running TW 7.2.

I cannot do the migration on that target, so I have exported my things from the old one.

I have used Export to SourceControlEntities -> this one is very nice, but it does not export Data..

So for data I've used Export To File -> Data ->All

I moved those files (SourceControl.zip) and Export Folder to the new system and imported.

First was Import from sourceControlEntities (I had to unpack that zip file and move to SystemRepository first), it allowed me to check diffs in my imported entitis. And than I imported data (I had to move that folder to Export folder and imported via ThingWorxStorage).

I ran into few error messages, but all and all, it works.

What is the correct procedure for System-to-system migration.

And what would you recommend as Best practice. To do it like this or make a new instance of the same TW version as it is on old machine, than export, import and than to use Upgrade Scripts and do the incremental Database updates??

Thanks a lot. 

PaiChung
22-Sapphire I
(To:tcoufal)

Probably nice to have this in a new thread, but the online instructions are fairly clear on this.

Export to ThingworxStorage and then import from ThingworxStorage (after installing the appropriate extensions)

Up to this point we've always provided upgrade/migration code within the platform that triggers off the import from TW Storage

tcoufal
12-Amethyst
(To:PaiChung)

Thanks Pai,

we have had some issues with migration even with online instructions (part of it was that vocabulary issue) that is why I am asking.

I dont quite follow what you mean by this:

Up to this point we've always provided upgrade/migration code within the platform that triggers off the import from TW Storage


Could you elaborate?

Top Tags