gpt4 book ai didi

javascript - 是否有将用户生日设置为 null、空或默认值的解决方案?

转载 作者:行者123 更新时间:2023-11-30 20:29:02 28 4
gpt4 key购买 nike

我为用户设置了生日。我需要删除这个生日,但我做不到。

我已经尝试过文档中的 PATCH 方法,但字段不能为空。然后我用 PATCH/PUT/DELETE 尝试了多次调用,但我总是有错误。

在 Delve 中,当我们删除生日时,它会变成 '0001-01-01T00:00:00Z'。我试图用这个值来修补生日,但我得到了未知错误:

{
"error": {
"code": "-1, Microsoft.SharePoint.Client.UnknownError",
"message": "Unknown Error",
"innerError": {
"request-id": "678fbda6-5fb9-4bc0-91c3-7af2238c1673",
"date": "2018-05-28T09:16:20"
}
}
}

最佳答案

我们可以使用下面的 SharePoint REST API 来设置用户个人资料的生日。

/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty

示例代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var requestHeaders = {
'X-RequestDigest': $("#__REQUESTDIGEST").val(),
"accept": "application/json; odata=nometadata",
"content-type": "application/json;odata=nometadata"
};

var userData = {
'accountName': "i:0#.f|membership|user@lz.onmicrosoft.com",
'propertyName': 'SPS-Birthday', //can also be used to set custom single value profile properties
'propertyValue': ''//set empty value
}

$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty",
type: "POST",
headers: requestHeaders,
data: JSON.stringify(userData),
success: function (data) {
console.log(data)
},
error: function (jqxr, errorCode, errorThrown) {
console.log(jqxr.responseText);
}
});
});
</script>

注意:修改上面代码中的“accountName”并将代码添加到 SharePoint 页面中的脚本编辑器 Web 部件中。

关于javascript - 是否有将用户生日设置为 null、空或默认值的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50563029/

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