Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Form Logger Script
- This topic has 0 replies, 1 voice, and was last updated 5 years, 1 month ago by Sam Moffatt.
-
AuthorPosts
-
October 9, 2019 at 10:41 PM #37038
Sam MoffattParticipantI had a need to get the script field ID which isn’t readily available in the Script Editor and decided to do a quick form script so that I could pick it up later. If you’ve used my ‘Script Manager’ form convention, then just create a new form script in it called ‘Form Logger’.
You can call it without arguments to get all fields dumped, here’s some sample calling code:
document.getFormNamed('Script Manager').runScriptNamed('Form Logger'); formLogger.dump()
If you want to filter by type, you can specify the field type:
document.getFormNamed('Script Manager').runScriptNamed('Form Logger'); formLogger.dump({'type': ['script', 'text']});
And this is it’s output in the console:
Form Logger: Shipments Type Filter: ["script","text"] Layout: default fld-c487390743c947969cbe661cff596855: text Tracking Number fld-0950c430cb0c41f79c51d43a544b366b: text Carrier fld-7a29242731d9451092c92d8586dbc94a: script Tracking Details fld-dddcdc15e1c44aa4a99bba6314dc7a07: script Tracking URL Autocomplete fld-9bee4fd0919e4b439e7bed8d5a6c1053: script Tracking Number Reformat fld-2cd0296ea0884c8cba3640d8e33f010b: script Checkbox Flip Flop fld-a9a09a61a9e949199e92d47c02fd364c: text Shipment Order ID fld-f7aba3b5ddd6430cb8e9a211e0086c84: script Date Propagation fld-45c8f29ec3214fc5aacbba73e2de3142: script Order ID FK
*Note:* This won’t look as formatted in the console because it uses a proportional font.
Here’s the full script, it’s pretty simple:
// ========== Form Logger Start ========== // // NAME: Form Logger // VERSION: 1.0.1 // CHANGELOG: // 1.0.1: Added support for custom form name and fix for "getId" rename. /** * Method to dump out the field ID's, type and names with the ability to filter by type. */ if (formLogger == undefined) var formLogger = (function() { return { dump: function({type = [], layout = 'default', formName = ''} = {}) { let targetForm = form; if (formName) { targetForm = document.getFormNamed(formName); } console.log('Form Logger: ' + targetForm.name); console.log('Type Filter: ' + JSON.stringify(type)); console.log('Layout: ' + layout); var fields = targetForm.getFields(); for (field in fields) { if (type.length == 0 || type.includes(fields[field].fieldType)) { console.log(fields[field].getId() + ": " + fields[field].fieldType + "\t" + fields[field].name); } } } } })(); // ========== Form Logger End ========== //
As you might gather, I want to have a layout additional filter but haven’t gotten there yet. Maybe in a later version.
-
AuthorPosts
You must be logged in to reply to this topic.