1

I am editing a SharePoint List using JS Link.

Within a SharePoint-Column, I would like to display information from another SharePoint column. The source is a SharePoint Person Column (Entliehenan).

enter image description here

When using the following script:

(function () {


    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = { 'Status': { 'View': CustomField } }; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

})();

function CustomField(ctx){
    var ret

    if (ctx.CurrentItem.Status) {
        ret = "<img style='height: 60px; width: auto;' src='~sites/100037/SiteAssets/Ampel/AmpelRot.png'></img><br><br><span style='background-color: #ffc7ce;'>lent to:&nbsp;" + ctx.CurrentItem.Entliehenbis + "&nbsp;an&nbsp"  + JSON.stringify(ctx.CurrentItem.Entliehenan) + "</span>";
    }
    else if (!ctx.CurrentItem.Status) {
        //ret = "<span style='background-color: #c6efce;'>Kann ausgeliehen werden</span>";
        ret ="<img style='height: 60px; width: auto;' src='~sites/100037/SiteAssets/Ampel/AmpelGRUEN.png'></img>"; 
    }

    else {

    }
    return ret;
}

(The responsible part in the script:)

JSON.stringify(ctx.CurrentItem.Entliehenan)

it returns

[{"id":"16","title":"Doe, John","email":"[email protected]","sip":"[email protected]","picture":""}] 

Now I would like to only display the Title of the JSON-object ("Doe, John").

How to do this?

I have tried to use:

JSON.stringify(ctx.CurrentItem.Entliehenan.title)

and

JSON.stringify(ctx.CurrentItem.Entliehenan[title])

but both return undefined.

4
  • If you are using SharePoint Online, are you open to use column formatting? Or is there any specific reason you are using JSLink? Commented Jul 11, 2019 at 6:19
  • Hello Ganesh. I am using the classic library view, as the modern has more limits for my generel Use-Case.
    – SteffPoint
    Commented Jul 11, 2019 at 6:22
  • Ok, Is the person or group field in single selection or multiple selection? Commented Jul 11, 2019 at 6:23
  • The Source Field: Person or Group (NO multiple choice allowed and persons only) ||| The Target Field: Date and Time
    – SteffPoint
    Commented Jul 11, 2019 at 6:26

1 Answer 1

2

Please Try using below:

ctx.CurrentItem.Entliehenan[0].title;

There is similar thread on MSDN forum: How to get people picker value using JS Link feature.

Also there is a nice article on Handling field values in JSLink:

Handling field values in JSLink.

Update(to Remove double quotes)::

You can use replace function in JavaScript as given here:

JSON.stringify(ctx.CurrentItem.Entliehenan[0].title).replace(/['"]+/g, '')
2
  • That's it, thank you so much!
    – SteffPoint
    Commented Jul 11, 2019 at 6:32
  • 1
    Welcome. glad it worked for you. Commented Jul 11, 2019 at 6:34

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.