Custom redirect based on items for user in a list

I have a list which records users responses, it's a basic list which contains three columns:

1.  Title of request (single line of text)

2.  User (people picker)

3.  Confirmed (Dropdown with a value of Yes and No)

Within the list, a user could have multiple items which they are assigned to as the "User".  Like so:

Request 1 | Doe, John | Yes

Request 2 | Doe, John | No

Request 3 | Doe, John | No

For this example we have three items in the list, all with the "User" of "Doe, John", two with a value of "No" for "Confirmed" and one for "Yes".

What I'm looking to do is to create a redirect page, on this page I'd like to have a query which will call this list and look for any items where the current logged in user has a value of confirmed for "No"

QUERY LIST WHERE CURRENT USER = USER AND CONFIRMED = 'NO'

Now, based on the results of this query, if the there are any records returned, I would like to redirect them to page A, else redirect to page B.

Is this possible to do?

Any help would be most appreciated.

September 14th, 2015 3:54pm

Hi,

We can use REST API and jQuery Ajax to achieve it, please modify the code(change the listName) below, add the code into a content editor web part in the page.

<script src="http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
    
        var listName="CustomList7";
        
        var userId=_spPageContextInfo.userId;
        var requestUri = _spPageContextInfo.webAbsoluteUrl +
                      "/_api/Web/Lists/getByTitle('"+listName+"')/items?$select=User/Id&$filter=User/Id eq "+userId+" and Confirmed eq 'No'&$expand=User/Id";

        //execute AJAX request
        $.ajax({
            url: requestUri,
            type: "GET",
            headers: { "ACCEPT": "application/json;odata=verbose" },
            success: function (data) {
                if(data.d.results.length>0){
                	window.location.href="http://www.bing.com";
                }else{
                	window.location.href="http://msdn.microsoft.com";
                }
            },
            error: function () {
                //alert("Failed to get details");
                window.location.href="http://msdn.microsoft.com";
            }
        });
    });
</script>

Best Regards,

Dennis Guo

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 11:02pm