0

I am getting a TypeError that I cannot figure out for the life of me. I am unable to debug as my company forces IE11, and I do not understand its interface [I use Chrome, which I don't have access to]. The error states:

TypeError: Unable to get property 'CurrentItem' of undefined or null reference

I am trying to override both at the Item level, and two fields which are lookup columns. I cannot figure out why the projCat field and the project field are turning up null or undefined?

Here is the code:

(function(){

var itemCtx = {};
itemCtx.Templates = {};

itemCtx.Templates.Header = "<div id='container'><table><tr><td>Project Category</td><td>Project</td><td>Project Summary</td><td>Toolkit Compliance</td><td>Project Lead</td></tr>";
itemCtx.Templates.Item = ItemOverride;
itemCtx.Templates.Footer = "</table></div>";

itemCtx.BaseViewID = 1;
itemCtx.ListTemplateType = 100;

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);

})();

function ItemOverride(ctx) {

    var projCat = projectCat();
    var projSum = ctx.CurrentItem.Summary;
    var project = projectName();
    var projLead = ctx.CurrentItem.projLead[0].title;
    var projComp = ctx.CurrentItem.artCompliance;
    var html = "<tr class='content'><td><div id='projCat'>" + projCat + "</div></td><td>" + project + "</td><td>" + projSum + "</td><td>" + projComp + "</td><td>" + projLead + "</td></tr>";

        if (projCat == "Change Mangement") {
            $("div#projCat").addClass("cm");
        }

        else if (projCat == "Communications") {
            $("div#projCat").addClass("comms");
        }

        else if (projCat == "Modernization") {
            $("div#projCat").addClass("mod");
        }

        else if (projCat == "OBPI Support") {
            $("div#projCat").addClass("obpi");
        }


        else if (projCat == "Process Improvement") {
            $("div#projCat").addClass("pi");
        }

        else if (projCat == "Project Management Standardization"){
            $("div#projCat").addClass ("pms");
        }
    return html;

}



(function (){
     var overrideCtx = {};
     overrideCtx.Templates = {};

    /* alert("Override worked");*/

overrideCtx.Templates.Fields = {
    "projCat" : {"View" : projectCat },
    "project" : {"View" : projectName }
};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function projectCat(ctx) {
    var output = [];
    var field = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

    if (field.length > 0) {
        var lookupValue = field[0].lookupValue;
    }
        output.push(lookupValue);
        return output.join('');
}

function projectName(ctx) {
    var output = [];
    var field = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

    if (field.length > 0) {
        var lookupValue = field[0].lookupValue;
    }

        output.push(lookupValue);
        return output.join('');
}
2
  • It seems like the context object is null / undefined.
    – Smile4ever
    Commented Nov 29, 2017 at 15:02
  • ..yeah I understand that from the error message; just not sure why since I thought I defined it in the function. Commented Nov 29, 2017 at 15:33

1 Answer 1

0

Realized I forgot to call the function on the current item (ctx). projectName(ctx); worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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