Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Javascript error on SharePoint page

$
0
0

Hi Team,

I'm updating a list column value by comparing a value of field from the same list using JS. It is working fine. But throwing javascript error on the page. 

Below is the snippet.

var web = null;
var clientContext = null;
var list = null;
var item = null;
var reviewStatus = null;
$(document).ready(function () {
    setInterval(function () {
        $Text = $("td.ms-cellstyle.ms-vb2:contains('No')");
        $Text.parent().css("background-color", "#FFb3BD");
        $("input[name='teamCheckbox']").change(function () {
            var controlid = $(this).attr("id");
            var parts = controlid.split('_');
            var itemID = parts[1];
            clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
            var list = clientContext.get_web().get_lists().getById(_spPageContextInfo.pageListId);
            item = list.getItemById(itemID);
            clientContext.load(item);
            clientContext.load(item, 'Status');
            clientContext.executeQueryAsync(Function.createDelegate(this, LoadStatus), Function.createDelegate(this, onQueryFailed));
            });
     }, 900);

    function LoadStatus() {
        reviewStatus = item.get_item('Status');
        if(reviewStatus)
        {			
            item.set_item('Status', 0);
            item.update();
            clientContext.load(item);
            clientContext.executeQueryAsync(Function.createDelegate(this, UpdateNo), Function.createDelegate(this, onQueryFailed1));
        }else
        {
            item.set_item('Status', 1);
            item.update();
            clientContext.load(item);
            clientContext.executeQueryAsync(Function.createDelegate(this, UpdateYes), Function.createDelegate(this, onQueryFailed1));
        }
    }
    function onQueryFailed() {
	alert("Request Failed at 1st asych");
    }
    function onQueryFailed1(){
	alert("Request Failed at 2nd asynch");
    }
    function UpdateYes() {
        //reviewStatus = null;
    }
    function UpdateNo()
    {
        //reviewStatus = null;
    }
 });

I'm getting the below JS error :

Message: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. URI: _layouts/15/sp.debug.js?rev=vK8qdKxCg9qccxdMK5Ebzg%3D%3D

    $Q_2: function SP_ListItem$$Q_2($p0) {
        var $v_0 = (this.get_fieldValues())[$p0];

        if (SP.ScriptUtility.isUndefined($v_0)) {
            throw Error.create(SP.ResResources.getString(SP.ResourceStrings.propertyHasNotBeenInitialized));
        }
        return $v_0;
    },

I have tried by calling the 2nd async query by changing to item.get_Context(); doesn't helped me.

Please suggest how to kill this error...

Thanks,

Bharath P N


P N Bharath


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>