0

I have the below code:

"use strict";

var Versiontitle = null;

(function (ns) {
    ns.itemHtml = function (ctx) {
        var returnHtml = "";
        ctx.ListSchema.Field.forEach(function (element, index, array) {

            var label = element.DisplayName;
            var value = ""

            if (element.FieldType.toLowerCase() == "taxonomyfieldtype") {
                if (!ctx.CurrentItem[element.RealFieldName]) {
                    value = "";
                }
                else {
                    value = ctx.CurrentItem[element.RealFieldName].Label
                }
            }
            else if (element.FieldType.toLowerCase() == "taxonomyfieldtypemulti") {
                if (!ctx.CurrentItem[element.RealFieldName]) {
                    value = "";
                }
                else {
                    for (var i = 0; i < ctx.CurrentItem[element.RealFieldName].length; i++) {
                        value = value + ctx.CurrentItem[element.RealFieldName][i].Label + ";";
                    }
                }
            }
            else {
                value = cgi.egov.csr.getDefaultFieldHtml(ctx, element, ctx.CurrentItem, ctx.ListSchema);
            }

            if (typeof value === 'undefined') {
                value = "";
            }

            returnHtml += "<tr><td width='20%' class='ms-stylelabel'>" + label + "</td><td width='80%' class='ms-stylebody'>" + value + "</td></tr>";

        });
        var versionsUrl = ctx.HttpRoot + "/_layouts/15/Versions.aspx?list=" + ctx.listName + "&ID=" + ctx.CurrentItem.ID;
        var returnHtml = returnHtml + '<tr><td><a href="javascript:OpenPopUpPage(\'' + versionsUrl + '\')">' + Versiontitle + '</a><td></tr>';
        return returnHtml;
    }
})(cgi.egov.commons.createNamespaceEGov('csr.metadtaView'));

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

    overrides.Templates.Header = "<table class='ms-listviewtable' width='100%' id='MetadataView'>";
    overrides.Templates.Item = csr.metadtaView.itemHtml;
    overrides.Templates.Footer = "</table>";

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

SP.SOD.executeOrDelayUntilScriptLoaded(function () {

    SP.SOD.registerSod("Res", "/_layouts/15/ScriptResx.ashx?name=Generic&culture=" + STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name));


    SP.SOD.executeFunc("Res", null, function () {

        Versiontitle = Res.version_history;

    });

}, "strings.js");

Sometimes I'm getting the value null for the version title. Then when I refresh its displaying it properly. After that it wont show null.

I don't where the problem is and the problem is not stable so that I can check where it is coming from. Am I doing something wrong like order of the resource loading or something?

0

One possible cause is that you are setting "null" as the second parameter to executeFunc. This may lead to some weird problems such as the function sometimes not being executed even when the file has loaded, or being executed too early, and the behaviour is random, since it is a race condition that depends on if the file has been loaded yet.

To know what value you should put, open the file you're loading and look for "Type.registerNamespace('Aaa.Bbb.Ccc');", or registerClass('Aaa.Bbb.Ccc'), or some other registration. The 'Aaa.Bbb.Ccc' is what you need to pass. I am fairly sure the value you are looking for is "Res".

Compare with some other working examples:

SP.SOD.executeFunc("sp.core.js", "SP.UI.AspMenu", .....);

SP.SOD.executeFunc("sp.js", 'SP.ClientContext', ....);

SP.SOD.executeFunc("sp.taxonomy.js", "SP.Taxonomy", .....);

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.