How to display a image from repository in the calculation

I have a calculated Media field. If the file extension field is .jpg then the calculation returns the media field value. If the extension is .doc then it returns an image from media as return “media:///doc.jpg”. But the doc.jpg is not displayed properly in the calculated media field. Any idea why?

Thanks

Can you show us your complete calculation?

Here it is,

if (file_extension == "jpg" || file_extension == "gif" || 
    file_extension == "png" || file_extension == "bmp") {
   return media_content;
}
else if (file_extension == "mov" || file_extension == "mpeg") {
   return "media:///iconMovie.jpg";
}
else if (file_extension == "mp3" || file_extension == "wav" ||
         file_extension == "ra" || file_extension == "rm" || 
         file_extension == "ram"
        ) {
   return "media:///iconAudio.jpg";
}
else {
   return "media:///iconOther.jpg";
}

To fix this issue I have changed my calculation as follows:

changed the code return “media:///iconMovie.jpg” to global_to_sysadmin.icon_video

The global_to_sysadmin relation is a global relation to a single record table where I store the icons in the media field.

if (file_extension == "jpg" || file_extension == "gif" || 
    file_extension == "png" || file_extension == "bmp") {
   return media_content;
}
else if (file_extension == "mov" || file_extension == "mpeg") {
   return global_to_sysadmin.icon_video;
}
else if (file_extension == "mp3" || file_extension == "wav" ||
         file_extension == "ra" || file_extension == "rm" || 
         file_extension == "ram"
        ) {
   return global_to_sysadmin.icon_audio;
}
else {
   return global_to_sysadmin.icon_other;
}

Any way to do this from the repository, as you tried originally?

Any way to do this from the repository, as you tried originally?

actually I think it was my mistake.

The code return “media:///iconMovie.jpg”;

which is returning a string while the calculation field type is set to media.

you may use

return plugins.http.getMediaData(“media:///iconMovie.jpg”);

But I am not quite sure about the efficiency of this method.

can any servoyians or gurus give me an idea about using plugin within calculations as in the above calculation?

Will it be alright or cause severe issues?