Skip to main content
11-Garnet
April 19, 2023
Solved

Doubt in Creating Users using services

  • April 19, 2023
  • 1 reply
  • 2584 views

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

 

Best answer by nmutter

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 */
});

 

1 reply

16-Pearl
April 19, 2023

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 */
});

 

 

Rayon_1111-GarnetAuthor
11-Garnet
April 19, 2023

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 */,
});

 

 

 

nmutter16-PearlAnswer
16-Pearl
April 19, 2023

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 */
});