The 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?
What 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.
@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.
I 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]) and record in that scope is still the main record, getFieldValue for 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.
Hi 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 record will be the current record in the Table field.
Ok, 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.
There’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.
This 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
Hi 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 using utils.copyTextFromClipboard() to create the new technicians records.
JSON.stringyfy() and JSON.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&tricks
Has 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?
Ideally 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&tricks
Thanks 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.
Hi 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
This 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.
The 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.