Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 21, 2019 at 7:44 PM #38159
In reply to: Feature suggestion: connecting databases
Daniel Leu
ParticipantHi Courtney,
Instead of using export and import, a script could be used to capture all the new data and copy it to the clipboard using
utils.copyTextToClipboard(). Then in your main document, you could have a second script that gets this data usingutils.copyTextFromClipboard()to create the new technicians records.JSON.stringyfy()andJSON.parse()would be used to convert your captured data object into a string and to decode it again.If you want to follow this route, have a look at Sam’s elegant script where he copies data from one form to another without defining the fields: 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&tricksNovember 21, 2019 at 4:06 PM #38158Ron Kline
ParticipantHas anyone used script to copy the contents of a table field in one form to a table field in a linked form? Is it even possible?
November 21, 2019 at 9:39 AM #38154In reply to: Displaying linked fields
Daniel Leu
ParticipantIdeally it would be nice to show the actual field so that you could edit it.
Ahh… you want to edit the field at the same time? Just like that it’s not possible. You would need a helper script that copies edited code back to the child field.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 21, 2019 at 6:27 AM #38151In reply to: Table row index number
Stephen Abshire
ParticipantThanks for the reply you are quite helpful. While I do have a development background TapForms and JavaScript are new to me. Let me try with a photo so it may help out a bit.
Looking at the attached image with a table field named ‘Timeline’ I want to do the following:
Cost = Minutes * Hourly Rate (not pictured)
The ‘Timeline’ field seems to be an array of records (rows) and what I need to figure out how to do is get the array index for the currently selected row. JavaScript I believe has zero-based arrays so the index for the current row would be something like Timeline[7]. What I don’t know how to do is get the array index for the current row so that I can get the values to do the math. A crude pseudo-code may be like this:
Timeline[index].Cost = Timeline[index].Minutes * Hourly_Rate
So how do I determine what ‘index’ is or is there a different way to do this?
Attachments:
You must be logged in to view attached files.November 21, 2019 at 5:44 AM #38150Topic: Generating eMails with attachments
in forum Script TalkEddy
ParticipantHi Folks!
We are using TapForms also as a CRM-System.
Therefore we let TapForms generate Emails for us. We are using a script, that generates a “mailto” phrase including address, subject and body. This headers are collected from TapForms fields. This works great.
And here is the task:
Sometimes we have to send our clients/guests a PDF (standard contract-template, checklist etc.). Of course, we store these standard PDFs in our CRM-System, i. e. TapForms. But there is no way to generate an email with an attachment by using the “mailto”-method.
What we need is a button inside a form, that creates an email with an attached file, coming out of a attached-file-field.
Any ideas?
Thanks in advance, Eddy
November 21, 2019 at 2:54 AM #38147In reply to: Displaying linked fields
Martin Inchley
ParticipantThis technique, of course, doesn’t show the actual field you are referencing. It just gets its contents into a script field in the current form.
Ideally it would be nice to show the actual field so that you could edit it.
November 20, 2019 at 7:09 PM #38137In reply to: Table row index number
Sam Moffatt
ParticipantThe challenge with both table fields and the many side of link to form fields is that the ordering can change and is dependent upon the sort settings in the UI. What I ended up doing with my order items form (line items in an order) is use a script to set the line number:
var title = record.getFieldValue('fld-39ca9564ef2347ac93f933bc9a2316ac'); var order = record.getFieldValue('fld-c3a6725d7d9446da92bbb880ffe90a9e'); var order_items = order.getFieldValue('fld-9db0c7698499435ab6b18b7eb420e0ae'); var quantity = record.getFieldValue('fld-39379cdff743496f9a1ccbdc1ae56297'); var line_number = record.getFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b'); var note = record.getFieldValue('fld-d0cfab9ec09d497294fbd8b5b52caf16'); if (!line_number) { record.setFieldValue('fld-f95b68d488cb4b058bbf3de84e1a7c3b', order_items.length); console.log('Setting line number to ' + order_items.length); }This generally works ok, it’s not perfect, but sets a field in the form that I can then refer to later. I use this in particular to ensure that I can always get the correct order of line items for display.
November 20, 2019 at 4:50 PM #38136In reply to: Displaying linked fields
Daniel Leu
ParticipantScript fields are very powerful vehicles to fetch, format, and process data from different forms, among others.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 20, 2019 at 4:41 PM #38135In reply to: Displaying linked fields
Martin Inchley
ParticipantThat’s very helpful, Daniel. Because I came to Script Fields after first experimenting with Form scripts and the TapForms JavaScript API, I have up until now been using them to achieve an action rather than present a result.
November 20, 2019 at 4:30 PM #38133In reply to: Displaying linked fields
Daniel Leu
ParticipantYou can do both with a field script.
1. Display a field from a linked form without it obviously being enclosed within the “Link to Form” field that was used to set up the link. I want it to appear like any other field on a layout.
var child_link_id = 'fld-c22501cc3910474aa1c59387fde30d82'; var child_name_id = 'fld-8b8f3b0cd59b4b4c9180a8903685e7ee'; var childs = record.getFieldValue(child_link_id); // show first child childs[0].getFieldValue(child_name_id);First I define the child link field id (in the parent form) and the name field id from the child form. Next I fetch all childs. Assuming I only have one child record, I just fetch the name of the first record found.
If there is more than one child record, I can simply loop over them:
// combine child names var child_names = []; for (child of childs){ child_names.push(child.getFieldValue(child_name_id)); } child_names.concat();2. Display a field that is two links away. Form A links to Form B. Form B links to Form C. I would like to display a field from Form C on a layout associated with Form A.
If I want to get data form a child’s child form, eg grandchild, the process is very similar. Following script just returns the name of the first grandchild record from the first child record:
var child_link_id = 'fld-c22501cc3910474aa1c59387fde30d82'; var grandchild_link_id = 'fld-9d399af0d72b4c8fbc3cb95fa6127203'; var grandchild_name_id = 'fld-9485e9dd29474745acee87bb3a60fff5'; var childs = record.getFieldValue(child_link_id); // get grandchildren from first child var grandchildren = childs[0].getFieldValue(grandchild_link_id); // get name of first grandchild grandchildren[0].getFieldValue(grandchild_name_id);To get the ids for the granchield fields, I opened a field script in the child form and copied the necessary entries over to the field script in the parent form.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksNovember 20, 2019 at 2:25 PM #38131Topic: Table row index number
in forum Script TalkStephen Abshire
ParticipantI have a script field that is contained within a table field. Since there are ‘n’ rows in this table and the script executes within each row how do I get the index number of the current row so that I can use it within the script?
November 20, 2019 at 10:57 AM #38130In reply to: Text field ‘OnChangeEvent’
Stephen Abshire
ParticipantThank you and appreciate the code sample. This is actually what I was working on myself but I was having issues that you answered in another thread regarding setting field values that trigger scripts and using the third parameter of ‘false’ when writing field values. Once again appreciate the help!
November 20, 2019 at 6:55 AM #38125Topic: Check box which generates today’s date only
in forum Using Tap Forms 5Simon Inchley
ParticipantHi there. I trying to create a check box field (called “paid”) that then generates todays date in another field (called “date paid”) when checked. I used a calculation field for the “date paid” field and wrote this:
if( PAID =”1″;TODAY();0)
I turned the calculation result type to “date”. On the “date paid” field I turned the default date to dd/mm/yyyy which gets rid of the seconds.
It works great except for it shows 01/01/1970 when the “paid” field is unchecked, which I understand is to do with how when is calculated from time.
So my question is: is there any way for the calculation to leave a blank field if the date field is not checked, just giving me a date for when I check it? Or do I have to do this through scripting?
November 20, 2019 at 12:36 AM #38117In reply to: Text field ‘OnChangeEvent’
Sam Moffatt
ParticipantReposting because my original reply got flagged as spam.
I’m uploading a sample form template that shows what I mean. It has two fields in it, a text field and a script field. I also included the form logger script with an update that prints out field ID’s in Javascript variable syntax. That’s used at the top top populate the field ID’s because by default the script editor doesn’t expose script fields. I also use this syntax because it includes the form name which makes it easy to keep track of variables in larger documents with lots of forms and lots of fields. There’s a commented line to ensure that Tap Forms registers this script to the field that works even if the line is commented out. I then grab the text field and the contents of the script field.
For the script field, I check to see if it is set and provide a default dictionary if it isn’t set already. If it is set to a value, I assume it’s JSON and parse it back into an object.
Then at that point it’s a quick comparison of the deserialised JSON payload and your new one. I added a message in so you can see a note, always useful after the fact for some of these scripts even if you hide the field by default, you can unhide it to see what it has in it.
Lastly the script field ends with
JSON.stringifyto return a JSON string as the fields contents. This object can obviously contain what ever you want in it so if you have multiple values instead of setting multiple fields, you just return a value at the end of your field script with the data you need to keep track of from each execution.Sample execution:

Field script:
// Script Field State var script_field_state_formID = "frm-86fd53d1f9ab47548636fc2e2d1d0d35"; var script_field_state__main_field_fldID = "fld-2177d4bf8500482d8fc6242faa80c5e6"; // text var script_field_state__watcher_fldID = "fld-7e997368aef740f68f126d2c8509d148"; // script // Make sure the field is watched to pick up changes. //var main_field = record.getFieldValue('fld-2177d4bf8500482d8fc6242faa80c5e6'); var main = record.getFieldValue(script_field_state__main_field_fldID); var state = record.getFieldValue(script_field_state__watcher_fldID); if (!state) { state = {'previous':undefined,'message':'Initial setting'}; } else { state = JSON.parse(state); } if (state['previous'] != main) { state['message'] = `Field value changed from '${state['previous']}' to '${main}'`; state['previous'] = main; } JSON.stringify(state);Attachments:
You must be logged in to view attached files.November 19, 2019 at 11:25 PM #38110In reply to: Script Behavior Question
Sam Moffatt
ParticipantIt is possible that your script can be re-entrant if it watches multiple fields and you call
setFieldValueon one of those fields. There is a third parameter tosetFieldValuethat controls if scripts are executed, flip it to a falsy value and scripts won’t be executed from thatsetFieldValueinvocation. I used to write my own guards because Javascript instance is reused so you can share variables between the other scripts triggered bysetFieldValue. Photo fields can also exhibit the same behaviour but I there isn’t a flag to disable them. For those I try to ensure that the field ID is obscured to prevent Tap Forms from triggering my script field for it. -
AuthorSearch Results