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

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

Hi @AnubhavRitolia 

 

I need to generate the password within the script only. 

 

Please suggest 

 

Thanks

Hi @varma2 

 

You can use below link to set specific default value for Password:

 

current.user_password = "<default password>";

 

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

Hi @varma2 

 

Giving static password can be risky. Better generate random password and use it. You can use below code to generate password and set it :

 

var pswd = new PwdDefaultAutoGenPassword().generatePassword();
current.user_password = pswd;
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();

 

 var pswd = new PwdDefaultAutoGenPassword().generatePassword();

 

This line will store some random auto generated Password. 

 

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