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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Doubt in Creating Users using services

Rayon_11
10-Marble

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

 

ACCEPTED SOLUTION

Accepted Solutions
nmutter
14-Alexandrite
(To:Rayon_11)

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

 

View solution in original post

9 REPLIES 9
nmutter
14-Alexandrite
(To:Rayon_11)

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

 

 

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

 

 

 

nmutter
14-Alexandrite
(To:Rayon_11)

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

 

Great it's creating user thanks for your reply.

 

Now, 

From this code I can create user by changing name like user1 ,user2 and so on till any number of user now suppose if I have to create 400 user and whose  name like user1, user2 and so on..  then how can I proceed so for that do I need  Infotable as well  or only services

please tell me 

 

Thanks

 

nmutter
14-Alexandrite
(To:Rayon_11)

You can just use the service you had in your first post, using the for-loop to create the users. But using the CreateUser-service and its parameters instead of the CreateEntity service.

are you saying like this way :

 

 

var template = Resources["EntityServices"].GetEntityTemplate({
name: "UserTemplate" // Replace "UserTemplate" with the name of your user template
});

var result = "";

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

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

}

me.result = result;

 

 

like this way I have to write but it is showing error like can't find function CreateEntityTempalte in object com.thingworx.resources.entities.entityServices@bc1afe

nmutter
14-Alexandrite
(To:Rayon_11)

not sure what you did exactly. But from your initial code the service would look something like:

result = "";

for (var i = 1; i <= numberUsers; i++) {
	var name = baseName + i;
	var params = {
		name: name /* STRING */ ,
		description: "" /* STRING */ ,
		tags: undefined /* TAGS */ ,
		projectName: "PTCDefaultProject" /* PROJECTNAME */ ,
		password: undefined /* STRING */
	};

	Resources["EntityServices"].CreateUser(params);
	result += "User " + name + " created.\n";
}

it's missing checks like if the user already exists and other items. But in general I think it should work like this

Kudos to you I am so glad It worked 

You make me smile thanks a lot 

and also thanks for replying me on time so that I couldn't loose my motivation.

Now I am excited to learn more and more .

 

nmutter
14-Alexandrite
(To:Rayon_11)

Sure thing Happy to keep you motivated!

Announcements

Top Tags