How do I programmatically apply a Model Tag when using Resources["EntityServices"].CreateThing()?
I created a service to create Things programmatically from unbound remote Things. I modeled it upon the service created in the PTC University Learning Exchange tutorial, Programmatically Add Things and Automatically Assign an Identifier.
I extended the example a little bit, with the intent of adding model tags to the Things as they were created. Here's the code for my service:
var identifiers = { maxItems: undefined /* NUMBER */ }; // result: INFOTABLE dataShape: EntityList var result = Resources["DeviceFunctions"].GetUnboundIdentifiers(identifiers); for (var i = 0; i < result.getRowCount(); i++) { var sensorName = result.getRow(i).name; var params = { tags: [ { vocabulary: "Applications", vocabularyTerm: "ThingWorxTraining" } ] /* TAGS */ , thingTemplateName: "RemoteThing" /* THINGTEMPLATENAME */ , description: undefined /* STRING */ , name: "SteamSensor" + sensorName /* STRING */ }; // no return Resources["EntityServices"].CreateThing(params); Things[params.name].EnableThing(); Things[params.name].RestartThing(); var ident = { identifier: result.getRow(i).name /* STRING */ }; Things[params.name].SetIdentifier(ident); Things[params.name].RestartThing(); }My service creates the Things just fine. It doesn't tag my Things, though.
Here's what my, "tags," element looks like in the JSON param above:
tags: [ { vocabulary: "Applications", vocabularyTerm: "ThingWorxTraining" } ] /* TAGS */ To see what the ThingWorx Platform does, I opened up my developer tools, created a Thing, and watched what went across the wire. The request the Composer made to create my Thing contained the following JSON pertaining to the model tag:
"tags": [{ "vocabulary": "Applications", "vocabularyTerm": "ThingWorxTraining", "_magicPickerId": "d19dc787-cd85-4271-9d04-40719202e561" }]The only differences I see are:
- The keys are surrounded by double-quotes. This shouldn't matter; unquoted key names should be valid JSON.
- The system includes a _magicPickerId element. I'm guessing that's because it knew that Id already, and that I'm not required to supply it.
Is there a problem with the syntax of my params variable that's preventing application of the model tag to my new Thing?

