Oh, and the Script must be set to return a Text result.
You could actually parse the SIN numbers from one field, then format them using the script to display in another field.
Here’s code to do that. Make a new field and set the Field Type to Script. Paste in this code:
function formatSocialSecurity(val){
val = val.replace(/\D/g, '');
val = val.replace(/^(\d{3})/, '$1-');
val = val.replace(/-(\d{2})/, '-$1-');
val = val.replace(/(\d)-(\d{4}).*/, '$1-$2');
return val;
}
function Formatted_Sin() {
var sin = record.getFieldValue('fld-4289784906dd4822ab1b738c404ca783');
console.log(sin);
if (sin != undefined) {
return formatSocialSecurity(String(sin));//"135-71-1458"
} else {
return nil;
}
}
Formatted_Sin();
I didn’t make up the formatSocialSecurity() function. I Googled for it.
You would have to replace your Social Security Number field ID with the one from your own form.
The script requires the values to be Text, so this part converts it to a String: String(sin)
See if that works for you. You may need to modify the code a bit to get the right format for you.
Hi James,
There’s no function in Tap Forms to write to the file system from a script. But adding write ability is something I’d like to do at some point.
Although you can post to a web service, so maybe if you had some web service running on your Mac you could have that service write to the file system after receiving data from Tap Forms.
Thanks,
Brendan
Hi! Is it possible to have tap forms create a new folder in finder named using data from tap forms fields?
I would love to click a button in Tap Forms that would then create a new folder with a LastName_FirstName, then another folder inside with OrderNumber, Equipment Folder 1, Equipment Folder 2.
Thanks for helping me find out if this is possible via Apple Script or another method :)
James
Scripts don’t run when you’re just browsing records. Imagine you had a script that took a long time to execute and you ran it for every record that’s displayed. It would make browsing miserable.
So there’s no automatic way of triggering a script when clicking on a Saved Search. You would have to refresh the records list which would run every script on every record displayed.
Idea: how about assigning a keyboard shortcut to a script?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thinking about this a bit more…
Is there a way to auto-run a script based on a saved search? For example lets say I have saved a search that utilizes a rule that a particular field be non-empty. Additionally I have a saved search with a rule that specifies a field to be empty. Depending on which saved search I’m browsing records with, the script would “fire” either collapsing or expanding the section heading.
Basically, I’ve got a long default form with a section containing a bunch of fields that I’d prefer not to see (collapse section) unless there is information in one of the fields within the section.
Thoughts/ideas?
–
T.
Hi Brendan,
I was able to use your bit of code and get the Section to collapse based on whether or not another field was undefined. It works great thank you!
Now is there a way to get this script to “auto-run”? I’ve saved the script as a “form script” i.e. it’s not a script type field in the form but I have to manually run it each time. Ideally I’d like the script to run each time a different record is displayed i.e. collapsing/un-collapsing the section while browsing records.
Thanks again for your help.
–
T.
The example above just toggles the section opened and closed each time you run the script. You will probably have different logic.
I a real beginner with scripts in Tap Forms so am finding it difficult to collapse a section based on the contents of a field. Basically I’d like to collapse a section if another field is empty.
I see from Tap Form’s JavaScript API there is something that looks like it should close a Section Heading type field (field.isCollapsed = true;) but when editing a form script the Section Heading type field I want to control does not appear in the list of Available Fields. I was able to get the field ID from the Fields List but still cannot programmatically collapse the section.
I’d appreciate any tips on getting this to work. Thanks
–
T.
If you use a script, you can set the color of a record: record.setRecordColor('#cc9900');. Maybe that’s sufficient for what you want to achieve.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I guess one way to do this would be to have the URL invoke a form script instead, with recordId as a parameter. Script could then look up the record, find the type, select appropriate layout and then select the record. Seems like that would get me where I want to be.
–Richard
Thanks Brendan,
I’ve found that once I’ve applied styles to a Note field I can no longer paste plain text into it. There is no error in the console about this. It just doesn’t happen.
In the other sub forum you mentioned
I suppose you could make a record that has the settings you want in your Note field and then duplicate that record whenever you want to make a new record? You would need a bit of text in there, even a space character for the attributed string to remember its settings.
I’ve been trying that, but I can’t see a way to append text to it in your javascript API, and with the fact I can’t even replace it with plain text once it’s been styled is going to force me in the long run to figure out how to convert richtext into an NSAttributedString.
I have another idea for this I’m going to explore.
Hi Lane,
record.setNoteFieldValue() requires either plain text or an NSAttributedString. However, that rich text can’t really be converted to an NSAttributedString in JavaScript as far as I know. So you’ll be better off just using plain text.
brand new to javascript, but I’m reading a lot.
so, I have this richtext
{\rtf1\ansi\ansicpg1252\cocoartf2706
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 FiraSansCondensed-Regular;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\csgenericrgb\c0\c0\c0;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tqr\tx7117\pardirnatural\partightenfactor0
\f0\fs24 \cf2 <placeholder>}
I don’t quite know how to convert that to an object variable that can be used with setNoteFieldValue.