Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Attachment Exists Script?
- This topic has 2 replies, 2 voices, and was last updated 4 years, 6 months ago by Michael Tucker.
-
AuthorPosts
-
May 18, 2020 at 4:15 PM #40635
Michael TuckerParticipantI have a form for keeping track of purchases that have warranties so when something breaks I can go look in one place instead of needing to go round up old receipts.
I do most work on iPad. There is a second form for log entries, and the log can include attachments.
When using the primary form, and then accessing the secondary form — it is useful to know if there are attachments in the log. You can see on mac but not on iPad.
Usually the brief info in log is enough but if there were an attachment, it might bear opening the log to see and a flag there is an attachment to know to open the log becomes useful.
If there is a way to make a script to notice an attachment exists and then yield “Yes” that would be a one step process. But not sure how.
Currently I use a script that yields a number 1 if an attachment exists in field it looks at. Then a second calculation field looks at the script field and if the script field is 1, it gives a textual “Yes”.
The script shows errors but does not seem to impede the function.
Maybe someone knows how to improve?
Eliminate errors in script; perhaps consolidate all functions in the script to get “Yes” instead of running two fields to get the “Yes”.
Thanks, Mike
Attachments:
You must be logged in to view attached files.May 18, 2020 at 7:57 PM #40640
BrendanKeymasterHi Mike,
You could do this all in one script.
function hasAttachments() { var attachments_field_id = 'fld-......'; var attachments = record.getFieldValue(attachments_field_id); if (attachments.length > 0) { return "YES"; } else { return "NO"; } } hasAttachments();
When you call
record.getFieldValue(attachments_field_id);
Tap Forms will return an array of items. Then you just check to see if the length of that array is greater than 0 then you do have attachments.Hope that makes sense.
Thanks,
Brendan
May 20, 2020 at 3:02 PM #40664
Michael TuckerParticipantBrendan,
Had to play with field id format from what iPad entered — but finally figured it out. Right now it’s very foreign territory.
Much more elegant! And need just the one field…
Thanks Much for help!
Mikefunction hasAttachments() {
var attachments_field_id = ‘fld-……’;
var attachments = record.getFieldValue(‘fld-2636701e2fde43a7985ea62c479c1108’
);
if (attachments.length > 0) {
return “YES”;
} else {
return “NO”;
}
}hasAttachments();
-
AuthorPosts
You must be logged in to reply to this topic.