Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
March 29, 2020 at 1:27 PM #40095
In reply to: Batch processing timefield
Daniel Leu
ParticipantIt works well for me being in PDT. I even tried to set my computer to CEST and it reports the correct numbers.
Just curious, could you create a script like follows and report what you get in the console? I hope I got the field names right.
var tijdCET = record.getFieldValue(form.getFieldNamed('Tijd CET').getId()); var tijdUS = record.getFieldValue(form.getFieldNamed('Tijd US').getId()); console.log(JSON.stringify(tijdCET)); console.log(tijdCET); console.log(JSON.stringify(tijdUS)); console.log(tijdUS);Attachments:
You must be logged in to view attached files.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksMarch 28, 2020 at 12:51 PM #40080In reply to: IOS script bug
Abdullah AlQaseer
Participant1 thing more , printing the record in ipad doesnt seem to populate the script fields (even if they are already filled by refreshing the record )
Attachments:
You must be logged in to view attached files.March 28, 2020 at 12:40 PM #40079In reply to: IOS script bug
Abdullah AlQaseer
Participantclosing and opening the document didn’t fix the issue
I created the script on the Mac
refreshing the record populated the missing fields , but this way I have to do it for every record I create using the iPad
March 28, 2020 at 12:20 PM #40078In reply to: Script: Trigger new entry in child form or table
Sam Moffatt
ParticipantIf you check out my GitHub there is a tftools GIT repo with a number of PHP scripts that should run on any recent Mac (tested on High Sierra, semi frequently on Mojave and also on Ubuntu 18.04 with PHP 7.2). There are two backup tools, the first is a simple polling operation that grabs records as they change at the polling interval and the other one of those is a backup tool that uses CouchDB’s revisioning properties to try to retrieve all changes. You can use eithre to get a copy of almost all changes (assuming sufficient polling interval) made to a Tap Forms document. I generally use the simple one with an hourly snapshot interval. Caveat is you need to enable sync to CouchDB for it to work properly but beyond that it is stable (in theory you might be able to skip the CouchDB requirement but you’d have to track down the sync port from Tap Forms each time you open a document). I personally use it to keep an extra backup copy that let’s me also look back into time to pull back stuff that I break. Downside of this is that it’s all inaccessible from Tap Forms, you’d need some sort of bridge web service to get at that data from a script inside of Tap Forms.
If you wanted the data to be accessible inside of Tap Forms, you could create a second form within Tap Forms to store the changes. You would need to store a shadow copy of the record with the old values and you would need another form for your log with just the differences. The shadow copy could be an exact replica of your base form but that would be a pain to keep in sync and would result in a duplicate form for each form tracked. That’d be a little expensive but does have the advantage that you could debug it reasonably easily because Tap Forms would render the shadow copy. That leaves you with a form that would store a serialised copy of the records in a simpler form which would have the advantage that you could store what ever you need (curiously at that point you’re recreating a database like CouchbaseLite on top of Tap Forms which is running on CouchbaseLite). You need the shadow copy because Tap Forms doesn’t maintain the earlier copy so you need to do so to get the old version of the record. From there you could use field scripts to monitor all fields, deserialise the shadow copy, compare all of the fields, update the shadow copy with the new values that have changed and then persist the change to a logging form. The logging form I could see as having fields for Form ID and Name, the Field ID and Name, a field for a serialised copy of the old value and a field for a serialised copy of the new value.
You could leverage an external set of tooling to also write back into the CouchDB the change log and maintain the shadow copy outside of the Tap Forms database. That might make sense to be able to aggregate a number of related edits together into a single logical change because without the edit/save button enabled, every edit is automatically persisted and replicated to CouchDB (this is, in general, a good thing). This would remove the need to have a field scripts inside of Tap Forms to duplicate the data but would mean you’d be reliant on that infrastructure working.
March 28, 2020 at 12:14 PM #40077In reply to: IOS script bug
Sam Moffatt
ParticipantTry closing the document and opening it up again.
Where did you create the script? On the iPad or on the Mac?
Did you try refreshing the record on the iPad? If you drag down from the top of the record it should let you refresh the record and force all script and calc fields to be recalculated/executed.
March 28, 2020 at 6:17 AM #40069Topic: IOS script bug
in forum Using Tap Forms 5Abdullah AlQaseer
ParticipantI noticed that the script of a field only run in the mac app
when I create a record in ipad the script is not running (the script get the name of parent record)
I attached screenshot of record created in MAc and another in ipad app
note patient name and mrn are empty in iosI also attached screenshot of the script
any solution ?
Attachments:
You must be logged in to view attached files.March 27, 2020 at 11:50 PM #40064In reply to: Script: Trigger new entry in child form or table
Chris Ju
ParticipantThank you Sam for your contribution. I tried your scripts (Form Logger, Logger, etc.) and came up with the following idea:
Instead of historical values (by triggering new entries), the old and new values could be written to a log file (ideally on a log server), e.g.: modification date / form name / field / deviceName / old value / new value …
In the case that nothing is changed, log entry should not be made.
Do you think that would be possible?
Thanks
Chris(I’m unfortunately an absolute beginner in scripting, so your help would be really great …)
March 27, 2020 at 5:06 PM #40060In reply to: Script: Trigger new entry in child form or table
Sam Moffatt
ParticipantA thing I thought about a while back for detecting the change is to create a script that watches just one field each and referred to itself to detect changes to the field. Then you can use
runScriptNamewith some variables set already to have a common form script to handle the specific logic you need. That was only for fields in the same form, I’m not sure how well it’d work with table/child records propagating to the parent records but I think it should work for detecting changes within the same form. You could use something similar to call into the parent from the child for a link to form case, I’ve not spent as much time with table fields to know if that’d work.An example of a script field that refers to itself to retain historic state is in my checkbox flip flop script.
March 27, 2020 at 1:16 AM #40046In reply to: Script: Trigger new entry in child form or table
Brendan
KeymasterCalling
var field_1 = record.getFieldValue(field_1);will get you the value for field_1. That’s how you watch for the value of a field. You would have to list every field in your form like that in the script to watch them all.I understand what you’re wanting to do. But Tap Forms wouldn’t tell you which field was just edited. For every field you watch, Tap Forms would just give you its current value. Then you’d have to log that to your Table field or Link to Form field.
March 27, 2020 at 12:41 AM #40045In reply to: Script: Trigger new entry in child form or table
Chris Ju
ParticipantThanks, Brendan.
Add a Field Script to your form that watches for the value of another field that you’re wanting to change.
Can i watch all fields and if one was changed get the field name to pass on to the new entry in the child form?
(I hope it’s understandable ;-)
Thanks,
ChrisMarch 26, 2020 at 11:57 PM #40044In reply to: Script: Trigger new entry in child form or table
Brendan
KeymasterHi Chris,
Sure, you can do this.
Add a Field Script to your form that watches for the value of another field that you’re wanting to change. Then call the
record.addRecordToField(someRecord, field_id);function to add a record to your Table or Link to Form field.You’ll have to create the
someRecordrecord first, then populate it with your values, then call the above function.Then call
form.saveAllChanges();Thanks!
Brendan
March 26, 2020 at 11:41 PM #40041Topic: Script: Trigger new entry in child form or table
in forum Script TalkChris Ju
ParticipantHello everybody,
is it possible to trigger a new entry in a child form (or table) by changing any field in the parent form?
Then it would be ideal if the old value of the changed field could be transferred to the newly created entry in the child form (or table).
The aim is to track changes and preserve historical values.
Thanks in advance
ChrisMarch 26, 2020 at 4:06 AM #40024In reply to: Batch processing timefield
Hans
ParticipantThanks for your solutions. I’m not (yet) familiar with the scripting function so I tried the tip from Wolfgang first. Made a calculationfield and that gives the right time bij subtracting the 6 hours from the original timefield. Unfortunately the calculation fieldtype only has text, numeric and date layout, so there my plan gets stuck already.
I think I’m going to put my question in the Script-forum.March 25, 2020 at 6:58 PM #40013In reply to: change the text color of a field?
Brendan
KeymasterHi Wolfgang,
There’s no function to change the label colour from a Calculation field formula.
However you could do it from a Script field. And however again, changing the
lableColourproperty on the field will change it for all records though.If you enable the
Required Fieldoption on your field, then if a value is not provided, the field label will show in red automatically.March 25, 2020 at 11:32 AM #39999In reply to: Batch processing timefield
Brendan
KeymasterYes, this is one way to do it.
Another would be to write a Form Script that loops through all of the records, reading the value from the field, subtracting the 6 hours and setting the value back again on the field and then calling
form.saveAllChanges(); -
AuthorSearch Results