Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
October 25, 2023 at 5:05 PM #50041
Topic: Format date field in CSV file for import via script
in forum Script TalkVictor Warner
ParticipantSome time ago, I got help with how to import the data from a CSV file with a script (see the post at https://www.tapforms.com/forums/topic/using-javascript-to-import-csv-files/#post-45422).
One of the fields in the CSV contains a date in the form “01/01/1963”, and the aim is to import it into a date field in the form.
Although the script runs fine and imports the data in the CSV, the date field is not imported.
Because of the way the script was written, I do not know how to change the format of the date field so that the date field is correctly formatted for import.
Help would be very gratefully received.
October 20, 2023 at 12:39 AM #50008In reply to: Open record as result
David Gold
ParticipantHi Daniel (or OP)
I would like to be able to do this also. I have some code below (not sure exactly how to insert a code block). I’m trying to do what you’ve said in line 11 with function show_name. Basically I want to be able to search the name field and when I get a result (whether multiple or single by selection in prompter) it then opens the record in Tap Forms. Can you tell me how to make it work?
Really appreciate any help as my javascript knowledge is limited.
var myForm = document.getFormNamed(‘Test’);var records = myForm.getRecords();var search_term = Utils.copyTextFromClipboard();var result_count = 0;var results = [];var results_name = [];var selected;function show_name( name ) {form.selectRecord(name[0]);}function copy_result_multiple( name ) {if ( name == true ) {console.log( ‘Index:’ + results.indexOf( selected ) );console.log( results_name[ results.indexOf( selected ) ] );show_name( results_name[ results.indexOf( selected ) ] );} else {console.log( ‘Cancelled’ );}}function multiple_results( all_results ) {let prompter = Prompter.new();prompter.cancelButtonTitle = ‘cancel’;prompter.continueButtonTitle = ‘Show Name’;prompter.addParameter(‘Select Result ‘, ‘selected’, ‘popup’, all_results).show(‘Multiple Results Found’, copy_result_multiple );}function search_records( haystack , needle ) {var name_id = ‘fld-1acb38c0b51b44698849501407b51722’;var rec;for (rec of haystack) {var name = rec.getFieldValue( name_id );if (name && name.includes( needle ) ) {results.push( rec.getFieldValue( name_id ) );results_name.push( rec.getFieldValue( name_id ) );result_count++;} else {if (! name) {console.log(“Empty field: ” + rec.getUrl());}}}if( result_count == 0 ){Utils.alertWithMessage(“No Results”, “No results were found for the search term: ” + needle);}else if( result_count > 1 ){//multiple resultsmultiple_results( results );}else{//single resultshow_name( results_name[0] );}}search_records( records , search_term );October 19, 2023 at 2:39 AM #50000Topic: Open record as result
in forum Script TalkPaul Hirst
ParticipantIf I’ve written a script to conduct a search and then at the end want to open the record that is the result of the search is there a way to do this? I have found the ability to print the result but that brings it up as a page to print rather than opens up the record?
October 18, 2023 at 6:41 PM #49998In reply to: Script to conduct a search
David Gold
ParticipantI’ve had a go at it cutting and pasting from some other scripts but can’t work out why it’s not working. Am getting an error in the console saying:
var myForm = document.getFormNamed(‘Boral’);
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var selected;function copy_name( name ) {
Utils.copyTextToClipboard( name );
}function multiple_results() {
var joined = ‘–multiple_matches–‘;
var res;
for (res of results) {
joined = joined +
res.name;
}
copy_comments( joined );
}function search_records( haystack , needle ) {
var name_id = ‘fld-1acb38c0b51b44698849501507b51722’;
var rec;for (const rec of haystack) {
if ( rec.getFieldValue( name ).toLowerCase().includes( needle.toLowerCase() ) ) {
results.push( { location: rec.getFieldValue( name_id ) } );
result_count++;
}}
if( result_count == 0 ){
console.log( ‘No results found!’ );
}else if( result_count > 1 ){
multiple_results();
}else{
copy_name( results[0].name );
}}
search_records( records , search_term );
-
This reply was modified 2 years ago by
David Gold.
October 18, 2023 at 1:10 AM #49995Topic: Script to conduct a search
in forum Script TalkDavid Gold
ParticipantI don’t know JavaScript so I was wondering if someone could help me with a simple script for the iOS app that does a search of a database for a term called “input” of a database called Boral with a form called Boral Data and searched a field called Name (I can add the field ID where it is needed)?
Any assistance would be much appreciated.
October 17, 2023 at 4:18 PM #49991In reply to: Calc fields / Tab
Brendan
KeymasterAlthough you could do it with a Script field instead of a Calculation field:
function Script() { // Replace with your own code var hello_world = "Hello\t\t\tWorld!"; return hello_world; } Script();October 12, 2023 at 9:54 AM #49979In reply to: Default layout font size
Glen Forister
ParticipantEarlier this week I made the same complaint, although a much longer explanation and description, but when I posted it, it disappeared, I thought maybe censored, but probably a glitch took me out.
Yes, there needs to be an addition to the settings for the main program to enlarge all the program’s fonts. I had to add an extra screen to my 14″ MacBook Pro because of this for all my programs, and it has helped a lot, but wasn’t enough help for Tap Forms. I often have to work with my total screen zoomed in via Ctrl / touchpad sweep 2 finger sweep up to magnify to a point where I am comfortable.
And, yes, this is a good program at a great price which almost replaces HanDBase which I had to move off of when Dave decided to quit.
Thanks.
-
This reply was modified 2 years ago by
Glen Forister.
September 28, 2023 at 1:33 PM #49936In reply to: Convert 2 fields
Brendan
KeymasterThere’s two places for scripts. Either a Script Field, or a Form Script. Both have their uses.
Script fields will get triggered to run whenever a value that the script field references is modified. Form scripts require you to manually run them.
Each have their uses. If you want something to happen whenever you change a value, use a Script Field. You don’t have to even display it as you can hide it. it will work silently behind the scenes.
If you had some sort of bulk process you’d like to do on all your records that you want to run manually, then use a Form Script.
September 28, 2023 at 12:37 AM #49930In reply to: Convert 2 fields
Michael Tucker
ParticipantYou can do it without scripts, I’ve attached a sample file.
Attachments:
You must be logged in to view attached files.September 26, 2023 at 6:12 PM #49924In reply to: Current Location via JavaScript?
Brendan
KeymasterHi Pinny,
I’m sorry, but I don’t have an API in Tap Forms to get the current location via JavaScript. I’ll see about adding one.
Thanks,
Brendan
September 26, 2023 at 3:09 AM #49918Brian Lennon
ParticipantI have one more question, hopefully a straight-forward one and best illustrated by the accompanying screen grab.
Field TRAININGold links to a form called TRAINING and contains the old data. The TRAINEEid is the reference code for this person in the PERSONS form that holds these fields.
Field TRAININGnew links to COURSES and is the intended destination of the new records. I have manually inserted a record using the tick at the bottom and selecting course coded 38 from the COURSES form. This is the action I want to script to complete data import and restructuring.
The question: If TRAININGnew links to courses as a join and sharing a common code, where is the common code in TRAININGnew? In TRAININGold, the TRAINEEid (137905) linked to TRAINcode 38, 62 and 78.
When I use the tick to show course 38 in TRAININGnew, it is obviously linking in some way to the TRAINEEid of 137905 but this shared link code is not visible in the linked table at TRAININGnew. Somehow I reckon I need to incorporate this invisible link into my script that attempts to replicate the tick action.
Once I have all the TRAININGold records transferred to TRAININGnew, my intention is to add new course records using the tick approach.
Thanks again
Attachments:
You must be logged in to view attached files.September 25, 2023 at 9:28 AM #49915Brian Lennon
ParticipantMany thanks Brendan – you capture exactly what I’m trying to do. I will follow your suggestions. I need to tune in more to the conventions of Javascript.
Great support!
Brian
September 24, 2023 at 12:38 PM #49912Brian Lennon
ParticipantBrendan – I feel I am presenting an issue that would probably use up too much of your precious time.
I’m still struggling with the syntax of javascript and am probably trying something that’s too far beyond my present capabilities though I did have success with some simpler scripts. (I feel like someone who has just started to learn English and is seeking help with an understanding of the grammar of Joyce’s Ulysses!)
Anyway, will attach the form template as requested.
My original database used 1:1 links from PEOPLE to TRAININGold (that just carried the person’s code and the course code) and this in turned linked to COURSES via the course code. I’m aiming to simplify this so that PEOPLE links directly to COURSES. With over 4,800 records in the database, a script is the only sensible way to process this import.
I’m not sure how much the template communicates so here are the current linkages:
Form PEOPLE > Field TRAININGold >>link 1:1 >> Form oldTRAINING (original data here)
Form PEOPLE>Field TRAININGnew>>link many:many>>form COURSES (wanting structure to use this link)
In the script I sent earlier I had changed the names of some variables to make them more understandable to myself and perhaps that was not the right thing to do.
If you can give me a few pointes in the right direction I’ll struggle on in my learning process.
Many thanks for your support.
Attachments:
You must be logged in to view attached files.September 24, 2023 at 11:17 AM #49911Brendan
KeymasterHi Brian,
So there are many issues with your code.
- This syntax is incorrect unless you actually have a form named
newTrainingId.var newLinkedForm=document.getFormNamed('newTraining_id');
- You weren’t using the variable
newLinkedFormanyway in the rest of your code. - The line
record.setFieldValue(newCode_id, oldTraining_code);is just setting the value on the same parent record over and over again.
It would help me to better understand what you’re wanting to do if you posted your form template so that I can look at your form structure and see if I can help you with the script.
September 24, 2023 at 6:59 AM #49909Brian Lennon
ParticipantBrendan – I tried to build in your suggestions but no luck so far. In fact, getting the different entries in the old record worked fine. Popping these into the new link doesn’t seem to work. Remember, I’m practically a total novice with Javascript so I’m probably committing massive mistakes. Here’s what I’ve tried so far with comments that hopefully give a clue as to what I’m trying to do. Any suggestions will be welcome but I acknowledge this may be a big job so don’t worry if you don’t have time.
//PURPOSE: restructuring imported data from earlier utility //to relocate a training course code to a different linked form //Getting list of existing training course codes for each person //from the old TRAINING linked form 1:1 function recordsLoop() { var oldTrainingForm_id = 'fld-732ad9dbc05249feac197450c84ef299';//incoming linked form var oldTraining_code_id = 'fld-f8bb7875bd094c4c94ea0ae98c5536d8';//course code id var oldTrainingValue = record.getFieldValue(oldTrainingForm_id); //var oldCodelist = [];//array to store incoming codes //new link (to COURSES form) to receive the code and so link to COURSES //the new training form is linked many:many var newTraining_id = 'fld-ac031e652f864a4a8ad98d20efb7f360'; var newLinkedForm=document.getFormNamed('newTraining_id');//not sure about this! var newCode_id = 'fld-549ed54657f94e81a9f1a3f0c4bff844';//field to receive incoming code for (var index = 0, count = oldTrainingValue.length; index < count; index++){//looping through incoming linked form var oldTraining_code = oldTrainingValue[index].getFieldValue(oldTraining_code_id);//get value of each incoming code if (oldTraining_code) {//if there is a code // read each course code from old TRAINING form console.log (oldTraining_code);//getting the right incoming codes here! They appear as a list in console //the bit that's not working //attempting to add the oldTrainging_code to the TRAININGnew link to form COURSES //My attempt to program what can be done manually by clicking the tick ("Select existing linked records") below the TRAININGnew table. //console.log("ACTION "+ oldTraining_code_id + "--" +newCode_id); //this looks like it does what I want ... but it does nothing! record.setFieldValue(newCode_id, oldTraining_code); } } return; } recordsLoop(); document.saveAllChanges();-
This reply was modified 2 years, 1 month ago by
Brendan. Reason: edited to add back ticks around the code
-
This reply was modified 2 years ago by
-
AuthorSearch Results