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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Creating Users from service - Issue creating Users

sabharees
13-Aquamarine

Creating Users from service - Issue creating Users

Hi, 

I am creating users from service, I using now CreateUserWithOptions() from EntityServices.. 

after executing my service I am able to see users by using this service(custom service from ptc found via article - https://www.ptc.com/en/support/article/CS176431 )

 

```````

var params = {
tags: undefined /* TAGS */,
nameMask: undefined /* STRING */,
type: 'User' /* STRING */,
maxItems: undefined /* NUMBER */
};

// result: INFOTABLE dataShape: RootEntityList
var result = Resources["EntityServices"].GetEntityList(params);

``````

But not able to see users from composer and in users section too, if I search particular user which I created I am getting no results found in search box.

Also, I am not able to delete the user through service.

8 REPLIES 8

sabharees
13-Aquamarine
(To:Rocket_Max)

Hi Max,


I already following this method to create users, but I am not able to find users in composers.
also, I tried to delete users, deletion also not happening I am not able get username tried GetPropertyValues() also...
Users["testuser4@sabharees.com"].GetPropertyValues();

sabhz_0-1615878842396.png

 



@sabharees 

 

Please import the attached entity on your instance. After executing the service createUsers I am able to see the testUser1 on Users screen in composer(refer screenshot). I am able to delete the user as well after executing DeleteUser service. I tested on Thingworx 9.1.

After importing the entity, execute the services and let me know if the user gets created and is visible on Users screen or not.

SachinSharma_0-1615880157092.png

 

Hi Sachin, 

 

Thanks for this... previously I created users without username I perhaps because of that only I am not able to delete users. 

Please let me know to update username property by using anyother method, if i use default update method It will ask username. In my case it is null now because of this I am not able to update users.

@sabharees 

 

When you try to create a user without providing username it gives an error with both CreateUser and CreateUserWithOptions services, so how did you create users without username? There is a service UpdateUserWithOptions but it requires userName param. I don't think there is any other OOTB service to update the user properties.

Since, the username field is unique you can create new users if they haven't been created already and use the username field to fetch their records. 

I created separate data shape with field names as same as user extension properties then I added values according to that, please take a look on my attachment & below code. My service created users and I am able to see users by using GetEntityList() but not able to update or delete users.

 

var params = {
 infoTableName: "InfoTable",
 dataShapeName: "Test_UserOptions"
 };

 var infotable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
 var newEntry = new Object();
newEntry.lastName = 'test4'; // STRING
 newEntry.smsAddress = 'test4'; // STRING
newEntry.firstLogin = true; // BOOLEAN
 newEntry.applicationKey = undefined; // STRING
 newEntry.organizationSU = 'test 1'; // STRING
newEntry.firstName = 'test user sabhz'; // STRING
 newEntry.emailAddress = 'testuser4@sabhz.com'; // STRING
 newEntry.userName = 'testuser4@sabhz.com';
 var password = Resources["EncryptionServices"].EncryptPropertyValue({data: "Login@12345"});
 newEntry.password = password; //password
 newEntry.mobilePhone = '+91 123456789'; // STRING
 newEntry.isAdministrator = true; // BOOLEAN
 newEntry.name = 'testuser4@sabhz.com'; // STRING
 newEntry.language = 'en'; // STRING
 infotable.AddRow(newEntry);
 // no return
 Resources["EntityServices"].CreateUserWithOptions({
 userOptions: infotable
 });

@sabharees 

 

To update the user extension properties you can simply run Users[UserName].UserExtensionName

e.x. Users["testuser4@sabhz.com"].lastName = "TestForUpdatingLastName";
result = Users["testuser4@sabhz.com"].lastName;

 

I was unable to create a user with a blank userName even when I used a custom datashape. I ran below code to delete the user,

let params = {
name: "testuser1@sabhz.com" /* USERNAME */
};

// no return
var result = Resources["EntityServices"].DeleteUser(params);

 

Let me know if it doesn't work for you. Please not userName itself cannot be modified once created, if you want to change it you will have to either create a copy of the user and then update it or create a new user.

Thanks for your comments.

I tried to delete the users which I was created from my custom DS, but I am not able to delete the users. Also, composer wise created user or UserOptions ds wise created users are able to delete. 

Top Tags