gpt4 book ai didi

javascript - 现在在服务中设置使用脚本 API 创建的用户的密码

转载 作者:行者123 更新时间:2023-11-29 22:48:26 25 4
gpt4 key购买 nike

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

我已经尝试使用 Table API 和 Scripted Rest API 来做到这一点。虽然我能够创建用户(在 sys_user 表中创建一个条目),但创建的用户无法登录 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);

最佳答案

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

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

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

关于javascript - 现在在服务中设置使用脚本 API 创建的用户的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57917619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com