OL Learn

How to check a file exists in the datamapper?

I have a database (MS SQL) where each record has a field which points to the location of an image.
I want to check if the image file, in each record, exists on disk . If it doesn’t, I want to STOP Processing the record and generate a log file of all missing images.

The goal here is to only validate my datamapper, generate a log file of all records with missing images.and notify an external application which will pick the images and process if they are all present or alert an admin with the log of all missing images.

Can this be achieved with the datamapper?

You could use the openBinaryReader() function for this:

Make a Javascript based condition like so:

Code:

try {
  openBinaryReader('C:/temp/BACK-M-LT.jpg');
  true;  
}
catch(error) {
  false;
}

Then in your false branch, put an action step to stop processing the record.

Generating a log will be the harder part, I think.

What you could consider instead would be to continue processing but output the result of that check to a field. This would give you a datamapping that you could use to potentially generate said report and also return you an XML file that could be used to trigger the retrieval of the missing files.

1 Like

That’s an excellent idea!
I will try it but I can see how this would answer my question.
Many thanks.