Unable to display attached images in I.E. or Edge

I used the following code to display attached images in the display form:

fd.spRendered(function() {
	var listLink = 'https://{mysite}.sharepoint.com/sites/fire/Lists/SCBA%20Work%20Orders/Attachments/';
	var itemID = fd.itemId;
	
	var img = '';
	
	for (var i = 0; i < fd.field('Attachments').value.length; i++) {
		//img += '<center>';
		img += '<img class="img-attch" src="';
		img += listLink + itemID + '/' + fd.field('Attachments').value[i].name;
		img += '">';
		//img += '</center>';
	}
	
	if (img.length == 0) {
		img = '<center>No attachments</center>';
	}
	
	$('.imgs').html(img);

});

It works just fine in Google Chrome. However, in IE and Edge I get the following error:



I have discovered that the code works on the Edit form. Curious.

Hello @smithme,

In the Display Form you can get the Attachment name with this code:
fd.field('Attachments').value[i].FileName

In the Edit Froms it is:
fd.field('Attachments').value[i].name

So just use this script in the Display Form :slight_smile:

fd.spRendered(function() {
	var listLink = 'https://{mysite}.sharepoint.com/sites/fire/Lists/SCBA%20Work%20Orders/Attachments/';
	var itemID = fd.itemId;
	
	var img = '';
	
	for (var i = 0; i < fd.field('Attachments').value.length; i++) {
		//img += '<center>';
		img += '<img class="img-attch" src="';
		img += listLink + itemID + '/' + fd.field('Attachments').value[i].FileName;
		img += '">';
		//img += '</center>';
	}
	
	if (img.length == 0) {
		img = '<center>No attachments</center>';
	}
	
	$('.imgs').html(img);

});
1 Like