3

In my Task list I got a column named "Status" with 5 different choices,

  1. Not Started
  2. In Progress
  3. Deferred
  4. Waiting on someone else
  5. Completed

In my task, when it is set to Completed I want the Column status to show a picture. I've uploaded the picture to my site.

Using this formula I can set the choice to Completed and its fine, if I choose Not started I cant continue.

=IF(Status="Completed",TRUE,FALSE)

But, what I want to do is

="<DIV><imgsrc='"
 &IF(Status="Completed"
     ,"http://MY_SITE/SiteAssets/Status%20Images/statuscompleted.png"
    )
 &"'></DIV>"

If the status is Completed, it gets the picture and adds it to the status column.

My question is, I've been trying this for hours now and I cant seem to get it to work.

5
  • 1
    So what does not work? You don't specify what result you expect and what error you get. Have you set the datatype to Number? This trick for putting HTML in Formulas only works in Views, not in Forms or the Validation Formulas on Forms Commented Feb 16, 2016 at 11:45
  • When choosing completed on a task, I want it to show a picture instead of the text "Completed" in the column :)
    – Elinho
    Commented Feb 16, 2016 at 11:49
  • In a VIEW? or Form? Commented Feb 16, 2016 at 11:49
  • Oh sorry, In a View.
    – Elinho
    Commented Feb 16, 2016 at 11:50
  • I editted your formula with linebreaks (SharePoint will ignore those) but you typed imgsrc So there is a space missing there. And you can exclude the DIVs, they have no purpose. also note the missing FALSE clause will create HTML: src='FALSE' resulting in a broken image on screen (for the other Status values) Commented Feb 16, 2016 at 11:54

2 Answers 2

3

Note:

in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


Original answer:

You do not need the DIVs

And you may want to rewrite you code to produce a (Status) image for all Status values:

="<img src='http://MY_SITE/SiteAssets/Status%20Images/status"
&[Status]
&".png'>"

Do not forget to set the datatype to Number! This only works in Views not on Forms!

So you need images:

statusCompleted.png
statusIn Progress.png
etc...

When building Formulas it is good practice to work from within Notepad (or any decent text-editor) and format you code with Linebreaks and indentations.

Then copy/paste to SharePoint which will ignore all that formatting.

SP2013/Online : CSR

You can use JavaScript to render Views and Forms using SharePoints (new) Client Side Rendering techniques

The iCSR.js support library gets you started with CSR (JavaScript) development

CalcMaster Bookmarklet

I have answered a lot of Formula questions, they are all tagged with ICC (Inline Calculated Columns), easy to find with:

https://sharepoint.stackexchange.com/search?q=ICC

If you know (or want to learn) what a Browser Bookmarklet is; I have Open-Sourced code that makes Formula editting a bit easier; Main feature: it does a syntax check on every keystroke.

https://github.com/Danny-Engelman/CalcMaster

0

This Link would solve your issue

http://blogs.technet.com/b/jay/archive/2013/06/17/how-to-display-images-in-a-calculated-column-of-a-sharepoint-list.aspx

6
  • Doesnt work, when I put status Completed i got a error, "Coloumn Validationo Failed"
    – Elinho
    Commented Feb 16, 2016 at 11:00
  • Kindly try below formulas.. ="<DIV><imgsrc='"&IF([Status]="Completed","MY_SITE/SiteAssets/Status%20Images/…>" Commented Feb 16, 2016 at 11:30
  • ="<DIV><imgsrc='"&IF([Status]="Completed","MY_SITE/SiteAssets/Status%20Images/…>" Commented Feb 16, 2016 at 11:31
  • Didnt work, choosing "Completed" on the task give me Column Validation Failed
    – Elinho
    Commented Feb 16, 2016 at 11:39
  • @Ankitkumar, it is good practice here to not only paste links but also post (part of) the blog with the relevant code. That way the answers can be indexed by StackOverflow as well. Commented Feb 16, 2016 at 11:47

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.