While I am not a javascript programmer, I can usually read through simple javascript code and understand what is happening. I am trying to write a simple script to show or hide a link to form field based on the value of a checkbox. Unfortunately it does not seem to be working even though it runs clean in the console log. Is there any quirky bugs in relation to scripts and link to form fields. I have included my simple script for reference. Thank you in advance for any assistance you can provide, it is greatly appreciated.
function New_Script() {
// get the check box id
var the_check_box = ‘fld-25afad2179224c368867d5f688afe496’;
// get value of check box – checked or not
var checked = record.getFieldValue(the_check_box_id);
// get id of the link to form field
var bills_id = ‘fld-3af9c9d4356a4dbba70d1e09a6ef6db5’;
// check if the check box is checked or not
if (checked == true) {
// true condition;
console.log (“show bills”)
bills_id.hideField = false;
} else {
// false condition;
console.log (“hide bills”)
bills_id.hideField = true;
}
}
New_Script();
It would be great to be have a barcode scanning feature using the Prompter(). Than one could write a simple script and have the automation done as needed. This would enable very efficient inventory updates, among others.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hi Paul,
You really don’t need a script to do this sort of thing if you’re using the Mac version.
There’s an Advanced Find & Replace function under the Records menu which would let you set a value in all of the records for a specified field.
You can also use the Fill Down function from the Multi-Column List View by typing your value in the field in the first row, then selecting that cell and all the cells beneath it and then using the Fill Down function under the Edit menu.
Do you have the Mac version?
Thanks,
Brendan
I wanted to add a new field to a form and have it set to a default value. I can do this with new records but I have over 2000 existing records and wanted to add this default value to the new field in each existing record as well. I assume the best way to achieve this is with a script but I am not great with scripting. I assume it is a very short script so was wondering if someone would be able to provide the script to be able to do this. I can see the setFieldValues function but don’t know how I write the scripting to be able to cycle through each record and populate the relevant field.
It sounds like you have two main data structures:
- A master list of all of your people/contacts, presumably with their email address.
- A set of email types or ‘campaigns’ that you want to send to a subset of your contacts.
There are a few ways I’d model this: a really simple way with a single form, a way with two forms and a slightly more complicated way with three forms.
The base are your people or ‘Contacts’ and you say you’ll have multiple email types/campaigns. You’re wanting to see all of the types/campaigns that the contact is available for as a property of the contact so you could model this as a single form with a lot of checkboxes at the end. Not the worlds most elegant solution but if there isn’t any more data than if they should get this email or not, then keep it simple.
Now if there are more details about the email type or campaign, then this would bring us to the two form solution. The second becomes your ‘Campaigns’ form and stores the campaign details. I’d model it so that you use a Link to Form field type set to Many to Many with the Show Inverse and then for each contact you add them to the campaign. Then the campaign can give you a list of all of the people who are supposed to be targeted to it. The campaign could also contain the body of the email you wish to send as well.
The challenge with this is exporting the list out to a CSV/Excel file means that the linked structure is flattened. You could work around this by putting fields in the contact form for each of the email types/campaigns but at that point you might as well just have a single form. For export purposes you could use a script field to automatically export a list of which campaigns the person is a member of but that’d require you to use Excel to expand the contents of the exported data as a post processing step.
This brings me to the third option which is using three forms. We keep our “Contacts” form for the contact details and we keep the “Campaigns” form for the campaign detail and then we create a third form for targets of the campaign, let’s call it “Campaign Targets”. In the “Contacts” form we create a Link to Form 1:M field pointing to our “Campaign Targets” field with show inverse relationship ticked and in “Campaigns” we do a similar Link to Form 1:M field to “Campaign Targets”.
Now to link a person to the campaign, we can create a new campaign target from the contact record and then select the campaign we want to use or vice versa we can create new campaign targets from the campaign and pick the people to include.
There are a few advantages of taking this approach:
- You can get either all campaigns a person is in or all people that a campaign is targeting by going from their respective forms creating a natural export filter.
- You can add calculation or script fields into the link form with content from either parent form (contact or campaign).
- You can export a flat list of contact to campaign easily and do filtering in third party tooling.
The first and third options achieve what I think you’re after without requiring a script field though you might want to use a calculation field to pull in the data you care about from the other two forms.
Hopefully this helps :)
I think you can do everything in your master form. In the master form, add a tag field of type text. Then you can add tags for the different member groups. Use commas or spaces to separate them. Then have filters for the different groups. This way, a member can take part of several groups.
I use something very similar with a custom layout. To assign a tag, I use a script with a Prompter where I use a pre-populated list.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I’m testing Tap Forms now, trying to use it to update an email list. I have two sources:
– A master list of people
– A related list with a smaller number of email addresses. Members of this list should be sent a specific kind of email. So, this relationship would be one-to-one, right? That is, if Tap Forms had that as an option. Many addresses in the master list, though would not have related records here. I coded it as a JOIN with “Show Inverse Relationship” checked.
– In the future, there will likely be more of these lists for different email types. So, the same address could be linked to multiple times. But each relationship would still be one-to-one.
The objective is to export the master list along with that additional field showing a person should receive that kind of email.
I coded a calculation field in the master file as:
IFNOTEMPTY(Still::Email;”Y”;””)
I can see related records. But, the calculated field is blank. Any advice? Do I have to do this with scripts?
Thanks!
Gary
Hi Rocky,
I’m sorry but the Script function has no access to formatting the text within Note fields.
Thanks,
Brendan
I think I know the answer here, but thought I would ask. Is it possible to format data in a note field via code? Or when I create text and save it to a note field. Is it possible to send it tags that would format the data when creating via a script.
Thanks, rocky
A simple Calculation (number) field is warming my brain!
IF(Type = "Dividend";24;32)
“Type” is the name of a Script field which contains “Dividend” or one of two other values.
24 and 32 are two arbitrary numbers to help me sort things out.
With this Calculation, all the records have 24 in the Calculation field, no matter whether Type contains “Dividend” or one of the other values.
With IF(Type = "";24;32), all the records still show 24.
With IF(TaxYear = "1718";24;32), all the records in Tax Year 1718 show 24. The others show 32, as expected.
I can’t see what I’m doing wrong when referencing the field “Type”.
In multi-column view with “Show sections” enabled, when my records are sorted on a Date field, the sections are set automatically to include the records for each month. Is there a way of changing that default section period to, say, a year or a day?
I have a Script field that holds a record’s applicable tax year in 4-digit format (e.g. 1819). When I sort on that field to get some totals for a tax year, the multi-column view shows no sections at all. This is all regardless of showing/hiding Group summaries, and showing/hiding the Calculations row. Nor do sections show up if I sort (e.g.) on account number
Thanks, Brendan.
I tried that already by using var.toFixed(2),
but this is running in a TypeError: toFixed is not a function.
This happens only when the script is running over such an affected value, for other values toFixed is working.
It’s a byproduct of the use of the Objective-C doubleValue method. The formatting and rounding according to the decimal places and Number Format settings doesn’t happen until display time. But internally the value is as it is. You would need to perform some JavaScript rounding of the values yourself if you need to do that.
I know where you got this from:
https://stackoverflow.com/questions/27746418/send-email-with-attachment-using-javascript-for-automation
But that’s JavaScript for Automation. That is, from AppleScript (but using JavaScript instead of the AppleScript language).
That won’t work from within JavaScriptCore, which is what Tap Forms uses.
Hi Eddy,
Did you try this from within Tap Forms? I just tried, but I get Can't find variable Application error. I’m not sure that Application is supported from within the JavaScriptCore framework.