Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 5, 2019 at 10:44 AM #37818
George Cx
ParticipantHey everyone, thanks for the awesome responses.
First up, apologies to Brendan. I wasn’t trying to be unkind – TapForms is awesome – and is in pretty much every way far more flexible and cool than AT. Its amazing what you’ve created – and I only wanted to give an example to show what I was seeing, not to criticize – thank you for taking it in that spirit (and I’m rooting for your first billion! Lets have this conversation on your yacht!)
Second up – I’m sorry to be such a dummy, but I’m not quite sure how to make these scripts work their magic on iOS.
Firstly I went to one of the records, selected “run a script” from the top right menu, then pasted in Brendans code, saved it, then backed out, then went back in and ran the script. Much as monkeys throwing screwdrivers at a typewriter to write Shakespeare, it created the exact response I’d feared ie nothing, because I guess I’m not sure where the results are put, not sure how to figure out the specific variable names of my field ie var actors_id = ‘fld-984cf79ccafb45a381b0f95b0aa28e78’; var last_name_id = ‘fld-a907066570844290a27940d34de98b4f’; ie I’m assuming that long key is particular to the field of the record. (I note that Brendan and Daniel have different field references but I’m assuming thats because they ran this on their unique instances of their forms.)
Then I backed out and edited the form itself, added a “script field” pasted in the text. Then pulled up the record and there was the script field. But this time even the typewriter was undented – the field sure said script, but clicking on it didn’t seem to invoke anything.
If I could lean on everyone’s kindness and expertise one more time and assume you are teaching this code to a fifth grader (and not one of those really bright fifth graders) – is there a screencast or stepwise instructions that goes step by step through
a) how to set up the code so those long keys actually related to fields my system will recognize
b) where to paste said code
c) how to invoke, and where to look for the results (and/or how to set up a special field to capture results*)*What I’m sensing will/should happen is that the code goes into the “linked” field – scrapes the returned value (say store name) then pastes “store name” as text ideally in some dedicated field so it shows on the multi-column view – then you can search/filter on that text. Anytime you update that record, you run the script again to make sure the latest scrape is in that text field – am I close?
I could paste you a quick screen cast of my pitiable attempts, but just imagine a whole lot of nothing happening and you’ve got the gist.
Thanks again for the pointers on this, I’m hoping my cluelessness might help others on the forum.
Cheers y’all
November 5, 2019 at 10:26 AM #37815In reply to: Combining Date & Time Info
Daniel Leu
ParticipantMartin, the purpose of my script was just to show that you can get access to the field values using Javascript’s Date methods. I posted my response to your original question before I received your progress update :)
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 5, 2019 at 10:09 AM #37813In reply to: Combining Date & Time Info
Martin Inchley
ParticipantActually, Daniel, a couple of things about your script.
1. I think you need to usegetDate()rather thangetDay(), in order to get the day of the month, and not the day of the week.
2. In your final calculation, I think d and m are round the wrong way. Also the w3schools JS tutorial says to be alert for the need to add 1 to the month, because January = 0. But in my script, it works without it.var date_and_time_id = 'fld-a74f18a96d4c42489a40a367f54f45ee'; var date_id = 'fld-3ef5526b645947c89317b8272dffd659'; var time_id = 'fld-95075cb1f5604be59afbc73094591e7a'; var date = record.getFieldValue('fld-3ef5526b645947c89317b8272dffd659'); var time = record.getFieldValue('fld-95075cb1f5604be59afbc73094591e7a'); var m = date.getMonth(); var d = date.getDate(); var y = date.getFullYear(); var h = time.getHours(); var mins = time.getMinutes(); var compDate = new Date(y, m, d, h+1, mins) record.setFieldValue(date_and_time_id, compDate); form.saveAllChanges(); console.log(compDate)However, I do currently have to add an hour to the hours, because of the problem I flagged in another thread, to which no one has yet come up with an answer.
November 5, 2019 at 9:28 AM #37807Topic: Calling a field value from a record or another form
in forum Script TalkEddy
ParticipantDear Folks!
I don’t know, if this is a bug of if I am to stupid…
In a script I have to call some field values.
For fields in the same form this is no problem.
record.getFieldValue(…)But if I call a field from another form, I get a error message.
The editor produces this phrase to call the value:
“XXXX.getFieldValue(…)”
“XXXX” is the name of the form, in which is the field, we need the value from.The error message is: “ReferenceError: Can’t find variable”
Where is the mistake?
Thanks in advance,
EddyP.S: My momentary workaround is to create a calculation field in my form, that calls the field value that I need and than to refer in the script to that calculation field. Working, but not really clean.
November 5, 2019 at 8:51 AM #37800In reply to: Combining Date & Time Info
Martin Inchley
ParticipantI should clarify. Using
record.getFieldValue(fieldID)returns a date in the standard JavaScript output way. My problem is with extracting year, month, day (etc) values so that I can produce a new date object. I can’t see how to do this.November 5, 2019 at 7:44 AM #37798Topic: Combining Date & Time Info
in forum Script TalkMartin Inchley
ParticipantI want to combine the date from a Date field and the time from a Time field into a value that can be pasted into a Date/Time field.
Using
record.getFieldValue(fieldID)on either field type does not return a JavaScript Date Object, but a string with Date and Time info.Please does anyone know how to extract the year, the month number and the day from a Date field, and the hours and minutes from a Time field?
November 5, 2019 at 5:38 AM #37789In reply to: Calling a script with an AppleScript
Martin Inchley
ParticipantThank you, Sam. So I found that this code jumps me to the specified record:
var thisRec = form.getRecordWithId('rec-93d0352d75c64a638dced9515827ac95'); form.selectRecord(thisRec)Great! But my need is to get TapForms to recognise that the current record is “selected” when I call a script from AppleScript. So I tried:
var thisRecID = record.getId() var thisRec = form.getRecordWithId(thisRecID) form.selectRecord(thisRec)Running this script does nothing visible, of course, because it tells TF to go to the current record. My hope is that it would tell TF that the current record is indeed selected. But when I call this script from AppleScript, I get the same complaint in the console:
“Record ID testing: TypeError: undefined is not an object (evaluating ‘record.getId’), column:23, line:1”
I.e. it simply does not recognise “record” in line 1 as referring to the current record.
Any more ideas?
November 4, 2019 at 10:45 PM #37775Daniel Leu
ParticipantI had a similar problem the other day and just wrote a small script that concatenates the content of a child field. The result is shown in the script field. Since this is only a helper field and I don’t want to clutter my form, I set the hidden flag on the script field.
const wineryNameId = 'fld-3e98efea365847f3a2569700d679b4ed'; var winesLinkId = 'fld-30dd9906b79649b6b54c01603928901d'; function joinChildField(childLinkId, fieldId){ let entries = record.getFieldValue(childLinkId); var list = Array(); for (entry of entries){ list.push(entry.getFieldValue(fieldId)); } return list.join(', '); } joinChildField(winesLinkId, wineryNameId);In order for you to use this field script, you have to set the different field ids. wineryNameId is the field in the child form. winesLinkId is the linked field pointing to the child form.
The operation of this script is very similar to what Sam posted. It is simpler as it doesn’t contain any logging features. The only thing you have to do is updating the two field ids.
Obviously, it would be nice if search would go through child records, if requested. And then only show child entries that match.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 4, 2019 at 10:38 PM #37772Brendan
KeymasterHi George,
You’re right. Tap Forms does not search down multiple levels of relationships.
But you can work around that by writing a Field Script which loops through the child records and builds a string that can be displayed and searched on the parent form.
Use the Child Records Loop snippet to loop through your child records. Then pick out a value from the record to concatenate to a string. Return that value and then you will be able to search that string.
function recordsLoop() { var actors_id = 'fld-984cf79ccafb45a381b0f95b0aa28e78'; var last_name_id = 'fld-a907066570844290a27940d34de98b4f'; var actors = record.getFieldValue(actors_id); var last_names = []; for (var index = 0, count = actors.length; index < count; index++){ var last_name = actors[index].getFieldValue(last_name_id); if (last_name) { last_names.push(last_name); } } return last_names.join(); } recordsLoop();Probably not as convenient as what Air Table has. I just read an article in the BBC News that they’re worth a billion dollars now. So I suspect they have lots of engineers working on the app and can do some things that Tap Forms can’t do yet. I’m just 1 guy :)
Thanks,
Brendan
November 4, 2019 at 7:43 PM #37768Sam Moffatt
ParticipantI’m a little confused because if you have two forms, one for wines and one for stores, which have a many to many link between the two and you’ve ticked the “show inverse relationship” on both sides (make sure to toggle it if you changed the type to delete and recreate the field), then on both sides you should have a multicolumn list view embedded in your record that gives you what I suspect you’re after (e.g. when looking at a wine, you can see which stores you linked). Try setting Many to Many and then toggling the “show inverse relationship” option on the “Link to Form” side of the relationship. This should be ok on either a Mac or iOS though I always go and double check it removed the field after toggling it off and then going all the way back to toggle it back on (that’s much easier on the Mac).
On another tangent, I think this might be similar to an earlier thread on how to filter using fields in two linked forms. The suggestion I made there is that it might help to have a third form, in this case I’d probably call it “purchase”. The “purchase” form has a 1:M link from wine to purchase and 1:M link from store to purchase, maybe put a date in as well. Then you can use that inner form to track which store your wines came from and when.
It could also be that the indexing in general is problematic and you need to copy the values from the linked forms into the parent. I wrote an example of how you can use a script field to copy values from linked records to help them show up in indexing.
I think maybe the Link from Form field might have gotten fried so give that a spin first because this should be working. Otherwise the other ideas might help you out. I’d suggest the middle one is useful to do because it let’s you track individual purchases but maybe you’re less OCD than me :D Good luck!
November 4, 2019 at 7:10 PM #37765In reply to: constants / phrases datebase wide
Brendan
KeymasterWell in the next update of Tap Forms I’ve added the ability for you to get access to the Pick Lists, so you could use them that way if you like from a script.
November 4, 2019 at 10:49 AM #37755In reply to: Calling a script with an AppleScript
Martin Inchley
ParticipantI appreciate the help, but this is proving really problematic. If the record that I want to work with is the active record in the form, why does TapForms think the record is “undefined”, just because I’ve called the script from an AppleScript? The script works when I just run it from within TapForms, but I want a simple way to successfully call from AppleScript a script that will act with the current record.
In addition – testing out functions from the TapForms JavaScript API web page, I edited my script to read simply:
function New_Script() { form.selectRecord() } New_Script();Every time I run this script by clicking the “Run” arrow, TapForms crashes.
November 4, 2019 at 3:11 AM #37743In reply to: constants / phrases datebase wide
Eddy
ParticipantThanks for your idea, Brendan!
But what we need is a phrase, that we can use in scripts and fields.
Did you thought about equipping tapforms with the ability to have constants? – Somehow, we already have something like that. The picklists. So, that preferences window would be the perfect place, to store phrases to be used tapforms wide.
Regards, Eddy
November 4, 2019 at 3:04 AM #37741In reply to: constants / phrases datebase wide
Brendan
KeymasterWell, if you are creating a custom layout for your emails, you can add a static Text object to your layout and then type in whatever text you want to appear there. Such as your company address, email, phone number, etc. That text will appear on your custom layout for every record when you print/email your records.
That’s another idea.
But also Sam’s idea of having a single Form script to store a bunch of information like that which you can pull up from field scripts is a great idea too.
November 3, 2019 at 9:33 PM #37735In reply to: constants / phrases datebase wide
Sam Moffatt
ParticipantI’d probably use the
runScriptNamedfunctionality and then define the common values in a form script. You then load the form script anywhere you need to use them and it’s a single place to change. That could be populated into a field that you can refer to from a calculation field or obviously it’d work natively in a script field. -
AuthorSearch Results