gpt4 book ai didi

javascript - 等待工作流程完成后再重定向

转载 作者:行者123 更新时间:2023-11-28 08:01:56 27 4
gpt4 key购买 nike

工作流程完成后,我需要将用户重定向到新页面。这是必需的,因为输入新表单数据后,我将用户重定向到显示表单,而不是将他们返回到“所有项目” View 。我需要完成工作流程,因为它会更新字段值和安全性。

目前,我将它们从新表单发送到重定向页面,该页面具有 JavaScript 函数来检查工作流程状态列是否已更改为 true。为了循环和检查,我只是再次调用相同的函数......这是非常非常糟糕的做法!使用 jQuery,我如何检查 SharePoint 工作流是否完成?我的初始破解代码如下:

SP.SOD.executeFunc("sp.js", 'SP.ClientContext', redirectNewItem);

function redirectNewItem() {

// REST call to get the current user
$.ajax({
async: false,
url: "/sites/mysite/_api/web/currentUser",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (user) {

//Get the user ID
var userID = user.d.Id;

// REST call to pass in the current user to get the most recent item created by the user. This is to ensure that the redirect goes to the item they just created after the workflow setting field values and security has completed.
$.ajax({
async: false,
url: "/sites/mysite/_api/web/lists/getbytitle('mylist')/items?$filter=AuthorId eq " + userID + "&$top=1&$orderby=Created desc",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {

//Get the user ID
$.each(data.d.results, function (index, value) {
var itemID = value.Id;

var redirectURL = "/sites/mysite/Lists/mylist/DispForm.aspx?ID=" + itemID

if (value.WorkflowComplete == "True") {
// Redirect to display form with correct ID

window.location.replace(redirectURL);
}
redirectNewItem();
});

},
error: function (data) {
//output error HERE
alert(data.statusText);
}
});
},
error: function (user) {
//output error HERE
alert(data.statusText);
}
});
}

最佳答案

我通过更改函数调用以包含 5 秒的超时来使其工作。循环直到条件语句为真。我还更新了代码以从页面上下文获取 userID,而不是使用 REST 调用:

SP.SOD.executeFunc("sp.js", 'SP.ClientContext', redirectNewItem);

function redirectNewItem() {

//Get the user ID
var userID = _spPageContextInfo.userId;

// REST call to pass in the current user to get the most recent item created by the user. This is to ensure that the redirect goes to the item they just created after the workflow setting field values and security has completed.
$.ajax({
async: false,
url: "/sites/mysite/_api/web/lists/getbytitle('mylist')/items?$filter=AuthorId eq " + userID + "&$top=1&$orderby=Created desc",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {

//Get the user ID
$.each(data.d.results, function (index, value) {
var itemID = value.Id;

var redirectURL = "/sites/mysite/Lists/mysite/DispForm.aspx?ID=" + itemID

if (value.WorkflowComplete == "True") {
// Redirect to display form with correct ID

window.location.replace(redirectURL);
}
setTimeout(redirectNewItem, 5000);
});

},
error: function (data) {
//output error HERE
alert(data.statusText);
}
});

}

关于javascript - 等待工作流程完成后再重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25274407/

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