Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 等待工作流完成后再重定向_Javascript_Jquery_Sharepoint_Sharepoint 2013 - Fatal编程技术网

Javascript 等待工作流完成后再重定向

Javascript 等待工作流完成后再重定向,javascript,jquery,sharepoint,sharepoint-2013,Javascript,Jquery,Sharepoint,Sharepoint 2013,一旦工作流完成,我需要将用户重定向到新页面。这是必需的,因为输入新表单数据后,我会将用户重定向到显示表单,而不是将他们返回到“所有项目”视图。我需要完成工作流,因为它会更新字段值和安全性 目前,我将它们从新表单发送到一个重定向页面,该表单有一个JavaScript函数来检查工作流状态的a列是否已更改为true。为了循环和检查,我只是再次调用相同的函数。。。这是非常非常糟糕的做法!使用jQuery,我如何检查SharePoint工作流是否完成?我最初的代码破解如下: SP.SOD.executeF

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

目前,我将它们从新表单发送到一个重定向页面,该表单有一个JavaScript函数来检查工作流状态的a列是否已更改为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秒超时,从而使其正常工作。这将循环直到条件语句为true。我还更新了代码,从页面上下文而不是使用REST调用获取用户ID:

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);
    }
});
}