立即在服务中设置使用 Scripted API 创建的用户的密码

Set password of user created with Scripted API in Service now

我现在是该服务的新手,正在尝试使用 Service Now 构建客户端 Web 应用程序。 我的要求是使用我的网络应用在 Service Now 中注册一个用户。

我已经尝试使用 Table API 和 Scripted Rest API 来做到这一点。 虽然我能够创建用户(在 sys_user table 中创建一个条目)但是创建的用户无法登录 Service Now 门户。

如果我以管理员身份登录并更改创建的用户的密码,该用户就可以登录。

请告诉我我做错了什么?

下面是我的脚本 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);

我找到了这个问题的线索。 当您在 gr.insert() 之前创建用户而不是设置密码时,请尝试按照以下代码更新设置密码的记录。

gr.user_password.setDisplayValue(requestBody.user_password);
gr.update();

看起来 sys_user table 中的密码是单向加密字段。所以需要设置显示值