The CreatorCon Call for Content is officially open! Get started here.

how to create user using background script?

munimohan1
Kilo Contributor

Please any one answer.

1 ACCEPTED SOLUTION

PrashantLearnIT
Giga Sage

Hi munimohan,



                                      var usr = new GlideRecord('sys_user');


                                      usr.initialize();


                                      usr.first_name= 'Prashant';        


                                      usr.last_name = 'Kumar';


                                      user.insert();



Mark answer as correct if it satisfies.....



Cheers,


Prashant


********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

View solution in original post

7 REPLIES 7

PrashantLearnIT
Giga Sage

Hi munimohan,



                                      var usr = new GlideRecord('sys_user');


                                      usr.initialize();


                                      usr.first_name= 'Prashant';        


                                      usr.last_name = 'Kumar';


                                      user.insert();



Mark answer as correct if it satisfies.....



Cheers,


Prashant


********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Hi Prashant,

Can you give me code(background script) for creating multiple users.

Deepa Srivastav
Kilo Sage

Hi,



Use insert() or initialize() function to create new record on sys_user table and set the required fields like user_name, first_name, last_name etc. (just FYI you need security_admin role to run background script).


                                        var newUser= new GlideRecord('sys_user');


                                      newUser.initialize();


                                      newUser.first_name= 'name';        


                                      newUser.last_name = 'lastname';


                                      newUser.user_name = 'empID';


                                      newUser.insert();



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Hi Deepa,

Can you give me code(background script) for creating multiple users .