cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

ThingWorx Navigate is now Windchill Navigate Learn More

Translate the entire conversation x

How do I know if an IMAGE property has a value?

dbologna
13-Aquamarine

How do I know if an IMAGE property has a value?

How can I check from JavaScript whether the content of an image property has a value or the default value 'image not available'?

BR

Dimitri

ACCEPTED SOLUTION

Accepted Solutions

Try like this

let hasImage = me.imageProperty.length !== 0;

If no image is set the length should be 0

View solution in original post

4 REPLIES 4

Try like this

let hasImage = me.imageProperty.length !== 0;

If no image is set the length should be 0

dbologna
13-Aquamarine
(To:nmutter)

HI All,

The solution proposed by mmutter works perfectly.

Many Thanks

BR

Dimitri

I would check if an IMAGE property has a valid value is to ensure it’s both defined and not empty. You can use something like this:

 

let hasImage = me.imageProperty && me.imageProperty.trim().length > 0 && me.imageProperty !== "image not available";

 

This covers:

  • the property being undefined or null,

  • empty strings, and

  • default placeholders like "image not available".

I dont think that there is a default value 'image not available'. you would get 0 length if an image is not set. 

 

If you’re using this check in a mashup or service logic, it ensures the image field is actually populated with a valid URL or base64 image data before you proceed.

abandal
12-Amethyst
(To:dbologna)

Hi @dbologna,


I wanted to follow up with you on your post to see if your question has been answered.
If so, please mark the appropriate reply as the Accepted Solution for the benefit of other members who may have the same question.
Of course, if you have more to share on your issue, please let the Community know so that we can continue to support.


Thanks,
Abhi

 

Announcements


Top Tags