Skip to main content
added 5 characters in body; edited tags
Source Link
Ganesh Sanap - MVP
  • 46.4k
  • 22
  • 31
  • 63

I am editing a SharePoint List using JSLinkJS Link.

Within a SharePoint-Column, I would like to display information from another SharePoint column. The source is a SharePoint Person Column ("Entliehenan"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"Title of the JSON-object ("Doe, John")("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"undefined.

I am editing a SharePoint List using JSLink.

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".

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.

added 178 characters in body
Source Link
SteffPoint
  • 807
  • 8
  • 29

I am editing a SharePoint List using JSLink.

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".

I am editing a SharePoint List using JSLink.

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 am editing a SharePoint List using JSLink.

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".

Source Link
SteffPoint
  • 807
  • 8
  • 29

Get certain field from returned JSON object

I am editing a SharePoint List using JSLink.

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?