How do I change the default img image displayed when a file is not found in a Print Context

The default image is a red circle with an X in the center. The customer would like none or an image of their choice. Currently this is html being created within the script manager with a new image tag, based on csv data.

I am hoping for a Connect solution / answer, as I would prefer not to script this in Workflow.

Hello, Iā€™ve check over the web and the following solution is neat:

<img onerror=ā€œsrc=ā€˜images/default.jpgā€™ā€ src=ā€œimages/theImage.jpgā€>

Default.jpg will appear whenever the main image is unavailable. You will have to add this for every images. At design you still see the X but at run time, the default image will show. Of course, make sure that the default image is available. Having it as part of your resources would be the most logical way.

I am trying that method and it is not taking.

I am not sure if itā€™s because I only have a print context or if itā€™s that, plus the html for the img tag is being built dynamically in the script pane.

Make sure to check the syntax since you are building it dynamically. HTML has a way of doing nothing when syntax is wrongā€¦double-check single-quote VS double-quote and so onā€¦

I moved over to a blank page and it was not what I was doing. Itā€™s a problem with the print context. It works with the web context.

I created a blank web context and a blank print context. Added the text below, but it only worked in the web context.

Anyone from OL want to shine in?

Unfortunatly, while going further into your request an actual limitation was found. It will be bypass in the future. Sadly I do not have a workaround as of now nor do I have an ETA to provide.

Thank you for looking into this further.

saturn

I always doā€¦even if it takes some timeā€¦:wink:

hello I think the on error function is still unavailable in this regard? Is there an alternative solution?

Found this post on the resource() functionā€¦

http://help.objectiflune.com/en/pres-connect-user-guide/1.8/#designer/API/resource.htm?Highlight=resource

Seems you can use the resource function to check if the file exists and just use some IFs to control which image is returned.

Hope this helps.

1 Like

In print context and control script, You can use Resource() function to check if current image in this path exists.

Otherwise create dummy.png image which will be small, white rectangle and replace it. (Place inside images folder)

var checkSignaturePath, results;

// path to signature
checkSignaturePath = record.fields.ChkSigFile;

// check if signature exists using resource() function
// if not then null will be returned
var resInfo = resource(checkSignaturePath);

// if our resInfo is not null
if (resInfo != null)
{
// render our signature
results.attr(ā€œsrcā€, ā€œfile:///ā€ + checkSignaturePath);
}
else
{
// if null has been returned then render fake dummy image
// image needs to be inside Resources/Images/ folder
results.attr(ā€œsrcā€, ā€œimages/missing.pngā€);
}

1 Like