Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 23, 2019 at 1:54 PM #38227
In reply to: Generating eMails with attachments
Eddy
ParticipantThanks Brendan, for your promt answer!
I found a way to generate mails from Tapforms to MacOS by using Javascript.
Like this:
Mail = Application('com.apple.Mail') message = Mail.OutgoingMessage().make() message.visible = true message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" })) message.subject = "Testing JXA" message.content = "Foo bar baz" attachment = Mail.Attachment({ fileName: "/Users/myname/Desktop/test.pdf" }) message.attachments.push(attachment)Or, even better by using the PATH-Command:
Mail = Application('com.apple.Mail') message = Mail.OutgoingMessage().make() message.visible = true message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" })) message.subject = "Testing JXA" message.content = "Foo bar baz" attachment = Mail.Attachment({ fileName: Path("/Users/myname/Desktop/if the file has spaces in it test.pdf") }) message.attachments.push(attachment)
The question is now:
How can I address the file / path inside Tapforms correctly?Thanks in advance:
Eddy
November 23, 2019 at 2:26 AM #38214In reply to: Advanced Find and Replace
Brendan
KeymasterBut also you could go into the Multi-Column List View mode, select all the values from one field, then click in the first cell of another field and paste. All the values will be pasted in order into the other field. Make a backup first in case it doesn’t do what you expect. Or the script that Sam posted.
There’s also the Fill Down function too which can be used to fill a value from the selected cell into all the selected cell below it.
November 23, 2019 at 12:53 AM #38209In reply to: Advanced Find and Replace
Sam Moffatt
ParticipantUse the script editor to grab the two fields ID’s and their values. For your old field, if it has a set of values then you need to translate them to the new value. I’d use a
switchstatement here on your old field to map it over, something like:let oldValue = record.getFieldValue('fld-1234'); let newValue = record.getFieldValue('fld-4321'); switch(oldValue) { case 'Swimming': record.setFieldValue(newValue + ', swi1', 'fld-4321'); break; }Then for your new field, if you have a multipick list then get the current value and then use JavaScript to append “, <new value>”. It’ll look a little weird ofr empty fields but shouldn’t hurt anything. If it is a single value pick list, then you can just reset the field value.
If you create a form script, you can use
form.getRecordsto get all of the records and then process them one at a time. A pattern I use is to create a function script that accepts a record field and then label it ascurrentRecordto avoid getting confused in the scope. Then I can test using a single record or later on put it in a loop.November 22, 2019 at 6:05 PM #38198In reply to: Form Script works, Field Script doesn’t
Martin Inchley
ParticipantGood spot, Daniel!
Unfortunately, adding it made no difference.:(
And the other script that makes the value appear when I trigger it manually makes no difference when I call it from within my Script Field script.
November 22, 2019 at 5:56 PM #38197In reply to: Form Script works, Field Script doesn’t
Daniel Leu
ParticipantI think you are missing a
document.saveAllChanges();at the end of the script.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 22, 2019 at 5:25 PM #38196In reply to: Form Script works, Field Script doesn’t
Martin Inchley
ParticipantLate night extra extra:
In this scenario, with the Paid box checked, the Calc field showing the Paid Date field is not empty, but the Paid Date field not actually showing anything – if I run a script to fetch the contents of the Paid Date field, the date suddenly shows up in it!
Similarly when I’m emptying it – the emptying only shows when I run a script to get the contents (and, worryingly, occasionally not even then).
Is this likely to be a time-lag in saving the data, or is there perhaps some trigger that’s not firing?
November 22, 2019 at 4:55 PM #38194In reply to: Form Script works, Field Script doesn’t
Martin Inchley
ParticipantExtra evidence:
Tinkering with this I set up a Calc field to hold 1 if the Payment Date field was not empty, and 0 if it was. After the Script field has been triggered by checking the Paid tick-box, this new Calc field is registering 1, even though the Payment Date field appears to have no content.
There would appear to be something in it, stirring beneath the waters…
November 22, 2019 at 4:28 PM #38193Topic: Form Script works, Field Script doesn’t
in forum Script TalkMartin Inchley
ParticipantThe following script is designed to put the current date into a Payment Date field when a Paid tick-box is checked.
var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b'; var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144'; var paid = record.getFieldValue(paid_id); var thisDate = new Date(); if (paid) { console.log(thisDate); record.setFieldValue(payment_date_id, thisDate); } else { console.log("no date"); record.setFieldValue(payment_date_id, ""); }When it’s run as a Form Script, it works fine. When it’s used within a Script Field, the console entries come in as usual, but the Date field doesn’t change, neither to get the Date nor to be emptied when unchecking the field.
If I set the If section to show the output in the Script field itself:
if (paid) { console.log(thisDate); thisDate; } else { console.log("no date"); ""; }the date appears and disappears as it should.
Am I missing something in how Script fields execute actions?
November 22, 2019 at 2:29 PM #38189In reply to: Advanced Find and Replace
Brendan
KeymasterWhat do you mean by populate some of that info into the field Summary? So you don’t want the entire value from your Quick Glance field to be put into the Summary field? But only part of the field value?
You could also write a Form Script to loop through your records, looking at field values from specific fields and populating your Summary field with whatever info you deem necessary.
November 22, 2019 at 1:43 PM #38188In reply to: Displaying linked fields
Brendan
Keymaster@Martin, that’s where the power of Scripting comes in. You can build scripts that expose the data further up the relationship chain from lower down. Although in general that’s a read-only thing. I agree though, it would be nice to be able to put editing controls in Tap Forms from anywhere down the relationship hierarchy. Doesn’t mean I’ll ever build that. But I understand the desire.
November 22, 2019 at 8:07 AM #38178In reply to: Table row index number
Sam Moffatt
ParticipantI think the challenge is with a table field, the calculation field only displays the fields from the record context. If you try to copy a field placeholder from a parent calculation field into the table calculation field then it doesn’t save right. If you create a script field in the table, when you insert the fields in the editor it includes the index format (e.g.
table_field_name[index]) andrecordin that scope is still the main record,getFieldValuefor fields in the parent form work but don’t work for fields in the current row of the table.At least in my testing, I couldn’t figure out how to get it to behave correctly.
November 22, 2019 at 1:25 AM #38169In reply to: Table row index number
Brendan
KeymasterHi Stephen,
I don’t think you need to index into this. Is your goal to do that simple multiplication, then all you need to do is add a Calculation field to your form that multiplies your Minutes field by your Hourly_Rate field.
You can also do it in a script:
function Cost() { var minutes_id = 'fld-abcd1234...'; var hourly_rate_id = 'fld-1234abcd...'; var minutes = record.getFieldValue(minutes_id); var hourly_rate = record.getFieldValue(hourly_rate_id); return minutes * hourly_rate; } Cost();The value of
recordwill be the current record in the Table field.November 22, 2019 at 1:16 AM #38168In reply to: Table row index number
Sam Moffatt
ParticipantOk, so I had to read this a few times and I’m still not sure I understand correctly but I did do some testing. I think you’re trying to calculate a cost based on the value in the table field and a value in a field outside of the table field?
I tried figuring out how to do this myself with a script field and couldn’t get it to work. I can sort of do it in a calculation field but only with fields from within the table. I might be missing something obvious, maybe I need to look later.
If you’re willing to restructure a little, I think you can do what you want a little easier with a Link to Form field though the script/calculation field in the table should be able to do that.
November 22, 2019 at 1:14 AM #38167In reply to: Generating eMails with attachments
Brendan
KeymasterThere’s no functionality for attaching a file to an email from within a Script.
However, on the iOS version, when you email a record, Tap Forms will include all photos and file attachments as attachments to the email. That functionality doesn’t exist on the Mac version though.
November 21, 2019 at 9:43 PM #38163Daniel Leu
ParticipantThis should be possible. I don’t see any reason why not.
Sam has a smart script to copy a record from one form to another. Copying from one table to another is very similar. Have a look at his script for inspiration: https://www.tapforms.com/forums/topic/script-to-copy-records-from-one-form-to-another/
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks -
AuthorSearch Results