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

@varma2 

either use mapping or record producer script.

Notification should be easy.

where are you stuck for password?

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

Hi Ankur,

 

Thanks for reply.

 

I have give below script to map the fields.

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();

 

But password how to Set the password im not aware of how we can set password.

And also that newly crated user we need to send the notification and assigne the "Star User' role.

 

Please suggest.

 

Thanks,

Varma

@varma2 

is user entering the password in some variable?

if yes then do this

rec.setDisplayValue('password', producer.passwordVariable);

Now you can assign role to that user by inserting record into sys_user_has_role table

You can have notification on sys_user table as usual and send the email

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

@Ankur Bawiskar 

There is no variable for user to entering the password.

It should be generate automatically.

Please suggest.

Thanks,

 

 

 

@varma2 

 

I have provided link on my reply to auto generate default password. Please check once.

 

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