Dynamic or conditional image display in Table view.

I have a form showing transactions in a locked Table view. In one column I want to show a little PDF icon where there is a PDF attachment file for that record. I have a Label/Button for that column, and the following code in the OnRender() event:

	var currAttachpath = event.getRecord().attachmentpath;
	
	if (currAttachpath)
	{
		var imageURL = '';
		
		// -- Return icon depending on whether attachment file actually exists.
		var attachmentFile = plugins.file.convertToJSFile(currAttachpath);
		if (attachmentFile.exists())
			imageURL = 'media:///pdficon_small.gif';
		else
			imageURL = 'media:///attachment_transparent.gif';
		
		forms.CustomerTransactions.elements.btn_attachment.imageURL = imageURL;	

	}

This produces odd results - some pages of the Table have the icon there for all records, some pages it’s gone, and it bears no relation as to whether there is an attachment or not …

Fixed it - I of course need to set the image against the object currently being rendered, obtained like this:

var thisButton = event.getRenderable();

Then once I establish what image to use:

thisButton.imageURL = imageURL;