Reputation: 110
I am new to the Service now and trying to build a Client Web-app with Service Now. My requirement is to register a user in Service Now using my web app.
I have tried to do so with Table API and Scripted Rest API. Though I am able to create the user (makes an entry in sys_user table) but the created user is not able to login on Service Now portal.
If I login as admin and change the password of created user the user is able to login.
Please tell me what am I doing wrong?
Below is my Scripted API -
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var requestBody = request.body.data;
var gr = new GlideRecord('sys_user');
gr.initialize();
gr.user_name = requestBody.user_name;
gr.first_name = requestBody.first_name;
gr.last_name = requestBody.last_name;
gr.title = requestBody.title;
gr.department = requestBody.department;
gr.user_password = requestBody.user_password;
gr.active = requestBody.active;
gr.email = requestBody.email;
gr.mobile_phone = requestBody.mobile_phone;
gr.insert();
//Create a body object. Add property value pairs to the body.
var body = {};
body.user_name = gr.user_name;
body.sys_id = gr.sys_id;
body.password = gr.user_password;
response.setBody(body);
})(request, response);
Upvotes: 2
Views: 893
Reputation: 341
I found a hook for this question. When you create the user instead of setting the password before gr.insert(), try updating the record for setting the password as per the following code.
gr.user_password.setDisplayValue(requestBody.user_password);
gr.update();
Looks like password in sys_user table is a one way encrypted field. So you need to set the display value.
Upvotes: 1