Need to create a User profile through Record producer?

varma2
Mega Sage

Hi All,

 

 

I need to crate recored producer which create the new user. We have 3 mandatory single line text variable in that item which is 1,first name 2. last name 3 email.

When user sumbit the item new user record should create with below fallow fields,

 

Create new active user in "ABC" domain
Set company to match company of user submitting request
Set userID to match email address
Set password
Set PW needs reset to TRUE
Add role "STAR User" to user
Send notification to newly created user with temp PW and instructions to login

 

Please suggest,

 

Thanks all,

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage

@varma2 

 

Firstly, Purpose of Record Producer is to create a record only. So once you submit Record Producer, it will automatically create User Record. No need to write script to GlideRecord and insert() else it will create duplicate.

 

You can use Default password for new users which you can send them through email to reset password. Please refer below link for it:

https://docs.servicenow.com/en-US/bundle/tokyo-platform-security/page/administer/security/reference/...

 

So now using script you just need to do few things: 

1) Set 'Password Needs Reset' to true - So once User login with default password, he/she has to reset password,

2) Assign "Star User" role (Support role name is - u_star_user).

 

Please find the code below:

 

current.password_needs_reset = true;
current.update();

var userID = current.sys_id;

var userRole = new GlideRecord('sys_user_has_role');
userRole.initialize();
userRole.user = userID;
userRole.role = <sys_id of Star User role>; // this you can store in System Property and call using gs.getProperty('<property name>');
userRole.insert();

 

 

Now you can create your Email Notification on User table on Insert to send Email to User's Email ID with Default Password Value and other details.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@varma2 

It's simple task and you can use variable mapping and record producer script to achieve this.

I would suggest you to start on this as it would be learning for you as well.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Thanks for reply.

 

I have done the varible mapping and also used the below script

 

ar rec = new GlideRecord('sys_user');


rec.initialize();
//rec.newRecord() ;


rec.first_name = producer.first_name;

rec.last_name = producer.last_name;
rec.user_name = producer.Email;

rec.email = producer.Email;
rec.insert();

 

Its creating the new records but its creating the duplicate.

 

And also it should 

Set password

And also it should add the role  "STAR User" to user.

And Send notification to newly created user with temp PW and instructions to login.

varma2_0-1666100198640.png

 

 

How can we add the role and also set the passaword.

 

Please suggest.

 

Thanks,

varma

 

 

 

 

Based on your needs it might make more sense to create a catalog item and trigger a flow to create the user, generate a password and send the notification. If you must do it from a record producer you'll have to register an event and have a notifcation triggered by that event. Then you should be able to script a call to the event with "gs.eventQueue()" and pass the user info and password. (Note: if you pass the password it could end up in the event log). 

Hi Ankur,

 

Any input on this stuck in middle. Need to generate the password as well need send notification below is configuration Thai i build.

Please suggest.

Thanks.