create ServiceNow User account (sys_user) from a catalog run script?

emyrold
Giga Expert

Looking for a way to create a user account from within a catalog run script. I found some inbound email examples but am not having luck translating this into a catalog run script.

Background:

New Hire Order guide with some basic new hire variables: (firstName, middleName, lastName, physicalRegion, physicalLocation, tmp_usr_record=true)

- We want to fill out the order guide with the tmp_requested_for variable = "New Hire" AND have 1-9 optional items selected. Then submit order and generate REQ and RITMs.
- The first RITM (New Hire) will have a run script (which I'm trying to figure out) that will create a ServiceNow contact record with just a few of the variables from above.
- After the partial user account has been created, then I want to dot walk to the parent REQ and change the "requested for" from "New Hire" to the newly created user record.
- Once the REQ (and the nested RITMs) have the new valid "requested for". then the approvals will start and the approvers will have the needed information to approve or reject the New Hire RITM.
- After both approvals, the following catalog tasks in the "new hire" RITM will be create AD account, then create/update ServiceNow contact record with the remaining new hire variable that will be asked on the "New Hire" maintain item. This last task can be manual at first and eventually automated.

***The thing I'm stuck on is the initial catalog run script to create the initial ServiceNow user record.

Any help would be really appreciated.

Thanks,

-Erik

11 REPLIES 11

Thank you so much Jay,

really appreciate it! working now!

-e


Hi Jay,

I think I got it, but was still interested in how you might do it using the sys_id.

Not sure if I'm using the GlideRecord methods correctly:

insertWithReferences():
initialize();
update();


Here is what I have:

[quote]

var usr = new GlideRecord('sys_user');

usr.initialize();
usr.first_name = current.variable_pool.new_emp_firstName;
usr.middle_name = current.variable_pool.new_emp_middleName;
usr.last_name = current.variable_pool.new_emp_lastName;
usr.title = current.variable_pool.new_emp_pos_title;
usr.u_user_type = current.variable_pool.new_emp_status;
usr.u_supervisor = current.variable_pool.new_emp_supervisor;
usr.phone = current.variable_pool.new_emp_phone_num;
usr.u_room_number = current.variable_pool.room_cube;
usr.insertWithReferences();
usr.locked_out = true;
usr.user_password.setDisplayValue("abc123");
usr.u_access_type.setDisplayValue("Employee");
usr.location.setDisplayValue(current.variable_pool.phy_loc);
usr.u_administrative_region.setDisplayValue(current.variable_pool.new_emp_admin_reg);
usr.company.setDisplayValue(current.variable_pool.new_emp_admin_org);
usr.u_correspondence_symbol.setDisplayValue(current.variable_pool.office_symbol);
usr.u_nh_temp.setDisplayValue("provisional user account");
usr.update();
[/quote]

Thanks,

-e