I need help, I'm very new to the SharePoint world.
I have a custom list for status indication with columns name as "Tool", "2017 q1" and "2017 q1-State". The "2017 q1-State" column has 2 options, "Ongoing" and "Terminating". How the list works is, based on the "2017 q1-State" value, the color of the content in "2017 q1" will change.
My Code (Reference link: Status Indicators on SharePoint Online):
(function () {
var StatusFieldContext = {};
StatusFieldContext.Templates = {};
StatusFieldContext.Templates.Fields = {
"2017 q1": { "View": Q1ValueFiledTemplate}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(StatusFieldContext);
})();
// This function reflects the background color and format based on respective status field value
function Q1ValueFiledTemplate(ctx) {
var q1x = ctx.CurrentItem._x0032_017_x0020_q1_x0020__x002d; //Assign Counter variable to q1 status value
var q1 = ctx.CurrentItem._x0032_017_x0020_q1;
// Return html element with appropriate color based on status value
switch (q1x) {
case "Ongoing":
return "<span style='background-color:#65FE18;display:block;width:200px;height:35px;'>" + q1 + "</span>";
break;
case "Terminating":
return "<font style='background-color:#F7FF02;display:block;width:200px;height:35px;'>"+ q1 +"</font>";
break;
}
}
Now, this code works fine for the list which has the same display and internal names, but it is not working for the lists which have different displays and internal names.
For your reference:
- Column 1: Display Name is Tool and Internal name is Tool
- Column 2: Display is "2017 q1" and Internal name is "_x0032_017_x0020_q1"
- Column 3: Display is "2017 q1-State" and Internal name is "_x0032_017_x0020_q1_x0020__x002d"
Can anyone please tell me what is going wrong in my code?