Is there a way to place a small JQuery/Javascript code to detect if an item list value is equal to yes and if so redirect the page using Content Editor Webpart?

If "Status=no"
 Then <meta http-equiv="refresh" content="0; url=http://example.com/" /> 

The hard part is reading the item list value and integrating that into JavaScript.


If I summarize your requirement, Then It is

  1. Get Items from a list using JavaScript
  2. Redirect to some URL

Get Items Using JSOM

You can use CAML query for this as you need to filter Status=no. So the query should look like

        <Eq><FieldRef Name=\"Status\" />
           <Value Type=\"Text\">no</Value>

Sample code

function retrieveListItems() {

    var clientContext = new SP.ClientContext('Site Url');
    var oList = clientContext.get_web().get_lists().getByTitle('List Name');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\"Status\" /><Value Type=\"Text\">no</Value></Eq></Where></Query></View>');
    this.collListItem = oList.getItems(camlQuery);


    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() +
            '\nTitle: ' + oListItem.get_item('Title') +
            '\nStatus: ' + oListItem.get_item('Status');


function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

For more explanation How to: Retrieve List Items Using JavaScript

Redirect to some URL

window.location.href = 'http://example.com/';
| improve this answer | |
  • Thank you Atish! Please forgive by letting me, since this is for one page, where do I place the code above? In a CEWP? Thank you! – Mike Rooker Jan 6 '16 at 15:45
  • This is a little new to me. Please tell me , is the aforementioned code to be placed in a CEWP. Furthermore I can't ascertain where the retrieved fields are stored. – Mike Rooker Jan 8 '16 at 14:54
  • From which page you need to redirect. You can put this code into that page – Atish Dipongkor - MVP Jan 8 '16 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.