1

I am stuck getting the name of the Author/editor.

I am overwriting the templates.item:

var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Item = newView.customItem;

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

In the customItem i am looping over the items and itemfields. This works oke, but not for the Author. The value for Author returns 1, instead of a name I was hoping for:

var newView = newView || {};
newView.customItem = function(ctx) {

var rows = ctx.ListData.Row;
    for (var i=0;i<rows.length;i++)  {

        var Html = "<tr class='itemRow'><td>";

        var fields = ctx.ListSchema.Field.length;
        for (var i=0;i<fields;i++)  {

            var thisFieldLabel = ctx.ListSchema.Field[i].DisplayName;
            var thisFieldName = ctx.ListSchema.Field[i].RealFieldName;
            var thisFieldNameValue = checkStatusKpi(ctx.CurrentItem[thisFieldName]);

            Html += "<tr class = 'fieldRow'>";
            Html += "<td class = 'fieldLabel'>" + thisFieldLabel + "</td>";
            Html += "<td class = 'fieldValue'>" + thisFieldNameValue + "</td>";
            Html += "</tr>";
        }
        Html += "</td></tr>";
     }
    return Html;
};

I did read and try posts without any luck:

  1. JSLink: Userfields (Author, Editor, ...) only provide userId not username and
  2. Create Edit Control Block (ECB) on View with JSLink

Trying to console.log without any luck:

console.log("Created by: " + ctx.CurrentItem["Author"][0].title); // value = undefined
console.log("Created by: " + ctx.CurrentItem["Author"]); // value = 1

Can anyone help me out with this, many thnx!

1

Make sure the author/editor field is displayed in the list view. Sometimes you might have to edit the web part and apply your view again after making changes to the view.

  • Thank you both. Editing the webpart didnt do it, but rebuilding the JS link did give me the object of the "Author" finally. – Yariev Jan 18 '16 at 14:17
  • The only code I removed was the looping over the rows. This was a overkill as I was editing "overrideCtx.Templates.Item". It didnt solve my problem, I think it must have been a caching issue. At least now I can check (in my case on checkStatusKpi) for an object and get the correct value of it as well: if (typeof currentValue === 'object') { currentValue = currentValue[0].title; } – Yariev Jan 18 '16 at 14:39
0

You need to use

ctx.CurrentItem["Author"][0].["title"]
-1

You could also use

ctx.CurrentItem["Author"][0].title

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.