Skip to main content
11-Garnet
Apr 19, 2023 7:55 AM UTC
Solved

Doubt in Creating Users using services

Hi, 

I am new in Thing Worx I have just completed thing Worx help center module and tried to  create 100 user in Thing Worx using services like I created a Thing Template and a Thing the I tried to write script code in services section of Thing Worx Template for creating 100 user and my code is like this way: 

 

 

var params = {
name: "UserTemplate", // Replace with the name of your template
description: "",
thingShape: "GenericThing", // Replace with the name of your thing shape
tags: ["UserTemplate"],
aspects: {}
};

var template = Resources["EntityServices"].CreateEntityTemplate(params);

var result = "";

for (var i = 1; i <= numberUsers; i++) {
var name = baseName + i;
params = {
name: name,
description: "",
template: template,
persistUserData: true
};

Resources["EntityServices"].CreateEntity(params);

result += "User " + name + " created.\n";
}

me.result = result;

 

but after executing this service I am getting error like:

TypeError: Cannot find function CreateEntityTemplate in object com.thingworx.resources.entities 

 

please help me and also give some brief advice on creating users using services like what entities we need to create this

Thanks

 

nmutterAnswer
17-Peridot
Apr 19, 2023 8:46 AM UTC

it is saying that it cannot find a variable 'user1' as you are referencing it in the 'name:'. For your test you would need to put quotes around the name, so it is a string, not a variable. Like you did for description e.g. 

Resources["EntityServices"].CreateUser({
	name: "User1"/* STRING */,
	description: ""/* STRING */,
	tags: undefined /* TAGS */,
	projectName: "PTCDefaultProject"/* PROJECTNAME */,
	password: undefined /* STRING */
});

 

9 replies

17-Peridot
Apr 19, 2023 8:15 AM UTC

Welcome to ThingWorx 🙂

 

You need to create users with a different service

 

Resources["EntityServices"].CreateUser({
	name: undefined /* STRING */,
	description: undefined /* STRING */,
	tags: undefined /* TAGS */,
	projectName: undefined /* PROJECTNAME */,
	password: undefined /* STRING */
});

 

 

Translate
Rayon_1111-GarnetAuthor
11-Garnet
Apr 19, 2023 8:34 AM UTC

Thanks for answering I have created new service and given user name as user1 but again getting error like:

ReferenceError: "user1" is not defined.

 

Resources["EntityServices"].CreateUser({
name: user1 /* STRING */,
description: "" /* STRING */,
projectName: PTCDefaultProject /* PROJECTNAME */,
});

 

 

 

Translate
nmutter17-PeridotAnswer
17-Peridot
Apr 19, 2023 8:46 AM UTC

it is saying that it cannot find a variable 'user1' as you are referencing it in the 'name:'. For your test you would need to put quotes around the name, so it is a string, not a variable. Like you did for description e.g. 

Resources["EntityServices"].CreateUser({
	name: "User1"/* STRING */,
	description: ""/* STRING */,
	tags: undefined /* TAGS */,
	projectName: "PTCDefaultProject"/* PROJECTNAME */,
	password: undefined /* STRING */
});

 

Translate