Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Showing web images
Tagged: Script
- This topic has 3 replies, 3 voices, and was last updated 5 years, 1 month ago by Tom Dropes.
-
AuthorPosts
-
September 28, 2019 at 5:29 PM #36888
Tom DropesParticipantHi all,
I’m trying to fetch a web image into a TapForms image field with “record.addPhotoFromUrlToField(url, fieldID);”, but I couldn’t find an example anywhere. Is there some script around for a start?
At the end I would like to use a TapForms URL field to enter the path, and get the image which is on the web-server loaded into the image field.
Thx a lot for your help
Tom
September 29, 2019 at 10:50 AM #36891
BrendanKeymasterHave you tried it just using the
record.addPhotoFromUrlToField(url, fieldID)
function and a hard-coded URL? WherefieldID
will be the ID of the Photo field.To get the URL value from another field, just double-click on the Website address field in the Script Editor and Tap Forms will generate code to get the value.
e.g.
var url_field = record.getFieldValue('some-field-id');
Don’t forget to call
form.saveAllChanges();
after.Thanks,
Brendan
September 29, 2019 at 10:51 AM #36892
Sam MoffattParticipantIf you’re looking to do a simple field, something like this should work as the contents of a script field. The first few lines set up some variables and get the current values. One thing to note that I use a variable to store the photo field ID because we’re going to use that again later. There is a basic sanity check that if the photo field is empty and the URL is set then go add to the field. If you don’t have this then it’ll keep trying to add to the field (photo fields support multiple images). This should let you delete the image and then if you change the URL again, it’ll download a new image to the field.
var photo_field_id = 'fld-1234'; var photo_field = record.getFieldValue(photo_field_id); var url_field = record.getFieldValue('fld-4321'); if (photo_field.length == 0 && url_field.length > 0) { record.addPhotoFromUrlToField(url_field, photo_field); }
I’ve just written this here on the forum, I haven’t tested it so there might be a bug. You’ll have to replace the field ID’s with your own fields but it should work.
September 30, 2019 at 10:01 AM #36899
Tom DropesParticipantFirst thanks a lot for the fast response. At the end I choose to use it as simple as possible. When changing the url in the field the new image will be edited to the viewer and the old image has to be deleted manually.
function load_image() {
var photo_field_id = 'fld-1234';
var url_field = record.getFieldValue('fld-4321');record.addPhotoFromUrlToField(url_field, photo_field_id);
}
document.saveAllChanges();
load_image();
-
AuthorPosts
You must be logged in to reply to this topic.