Show a link to a doc in a grid in dependence if doc exists

In every row of a grid I have a link to a pdf file. But not for every single record in the grid a pdf already exist so I would like to hide the link (which is a html image field) where no pdf exists and show the link image when there are pdfs in the db.

How could this be done? Is sc_field_display the right way?

Joe

Hello,

how about using a custom field? Take a look.

  1. Create a field from menu option and name it as “pdf”
  2. Click over the field recently created and put the following logic in the onExecute() event:

// image to display if not pdf is found
$imageUrl = 'http://example.com/notFound.png';

// assuming that there is a column called "pdf_file_url" then:
$pdfUrl = [pdf_file_url];

if ($pdfUrl != null && $pdfUrl != ''){
    // pdf exists, then show the link
    {pdf} = '<a href="'. $pdfUrl .'">' . $pdfUrl . '</a>';
else{
    // show the not found image
    {pdf} = '<img src="'.  $imageUrl . '" />';
}

  1. Go to Edit Fields in menu option and drag “pdf” field to drop it inside of shown fields section.

Now, your grid will have an additional column showing the image or the pdf link according to the case.

Hi Manfred, this is a very helpful solution. Thank you!