I’m dealing with a rather sensitive API that times out very often for me. This API returns images and I want to add those images to my forms. To do this I’m iterating over all the records and adding them. But due to the timeouts, sometimes my images don’t get added.
To go around this issue i’d like to count the number of images in a Photo field and if it’s > 0, skip it.
So far I haven’t even been able to access the Photo field. tt.getFieldValue(photo_id_charactersform);
returns undefined.
I have a workaround for this but i’d like to avoid it if possible, as it requires me to manually keep track of how many images a record field has.
You can count the number of photos in a Photo field like this:
var photos = record.getFieldValue(photo_field_id);
photos.length;
That’ll return the number of photos in the Photo field.
As long as the photo_field_id
evaluates to a proper field ID and record
is valid then it should work. For Photo fields, the getFieldValue()
function will return an array. So now you just need to get the length of the array.
Brendan,
I got it now. It returns an array when there’s photos, and undefined
when there’s nothing. I was expecting it to return an empty array in that case but I can adapt to this. Thanks.
Ah I see… Ya you would need to add a check for undefined too then. I suppose I could modify my code to return an empty array if there’s no photos.