Reaction in extension scripts when image does not exist

Use this Forum to post your “How to …” questions about your use of aXes. This is not a technical support forum. Both the aXes Support Team at LANSA and other aXes customers may answer your questions. LANSA cannot guarantee the accuracy of any information posted by customers.

Moderator: jeanmichel

Post Reply
Joerg Hamacher
Posts: 40
Joined: 09 Mar 2016, 00:29

Reaction in extension scripts when image does not exist

Post by Joerg Hamacher »

When expanding the displays with images, I put together the file names of the images from fields on the screen, here e.g. from DLART1 and DLVEL1.
The image file has the extension .tif - at least for now.
Now I get pictures both as .tif and as .jpg and would have to search alternatively, so to speak, once for DLART+DLVEL.tif and (if no result) again with DLART+DLVEL.jpg. Can this be controlled in the script?
CLIP-6B2C2B6C.JPG
CLIP-6B2C2B6C.JPG (24.34 KiB) Viewed 4821 times
Now there should be a reaction if the image in w_ImageName does not exist.
In this case I want to to use ".jpg" instead of ".tif".
Can this be done in aXes scripts?

Many thanks in advance and best regards,
Joerg
User avatar
Dino
Posts: 88
Joined: 19 May 2017, 08:29

Re: Reaction in extension scripts when image does not exist

Post by Dino »

Hi Joerg,

The next script works fine to identify if a file exist in a url. you just need to provide the relative path to the image, as the image is not located in the same folder as the script, and off course, before returning your final decision about what file to use, use the verifyFile() function to check if the file exist:

Code: Select all

function verifyFile(urlToFile) {
    var abc = new XMLHttpRequest();
    abc.open('HEAD', urlToFile, false);
    abc.send();
    if (abc.status == "404") { return false; } else { return true;  }
}
 
// Testing the verifyFile function
var result = verifyFile("/ts/skins/images/examplephoto.gif");
if (result == true)  alert('The file exist!'); else alert('sorry, not here!');
Joerg Hamacher
Posts: 40
Joined: 09 Mar 2016, 00:29

Re: Reaction in extension scripts when image does not exist

Post by Joerg Hamacher »

Hi Dino,

thank you very much for this example.

Best regrads,
Joerg
Post Reply