Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 2,296 through 2,310 (of 2,950 total)
  • Author
    Search Results
  • #37209
    Daniel Leu
    Participant

    Hmm… I never tried. Could be a fun project. BTW, the script language is called javascript. Java is a totally different programming language.

    To get started, you might want to take the movies example and adjust it to work with the books api at https://openlibrary.org/dev/docs/api/books.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #37208
    Matthew Johnson
    Participant

    Has anyone successfully made any templates that have scripted-in the ability to simply scan a book’s ISBN number and it fetches all of the book’s info and autofills out the form? I’m a compete beginner with Java, so that may be a bit much for a first time Java project. This could speed up the process of keeping a record of all of our books a bit easier.

    I think Brendan posted a script that worked this way for movies, and it worked rather well (except for the photo field), once I pasted my Field ID’s into the right spots. I haven’t seen anyone do this yet with ISBN though.

    #37184
    Sam Moffatt
    Participant

    If you’re feeling a little more adventurous, I created a sample form over in the scripting forum that uses a Link to Field “JOIN” type and some scripting to automate some of the work. You can pick up the form template and load it into an existing document to see how it works for you. It’s similar to Brendan’s idea above and you can sort of treat it that way as well if you want.

    #37182
    Sam Moffatt
    Participant

    On the main forum there was a posting about having a form for tracking health symptoms. I like Brendan’s idea but I also like to automate things and this one got me curious about using a Link to Form “JOIN” field instead. Whilst Tap Forms won’t let you run a script at record creation, you can create a script field attached to all of the fields in the form and use that to do some work.

    I’m attaching a template that has two forms in it: a Days form and a Log Entry form. The Days form has your “Days” in it and you can create a new day entry. There is a “Link to Form” field that links to the “Log Entry” form based on the “Date” fields. The date in the log entry record is “joined” to the date in the days record. If you create a new “Days” record, it will automatically set the date and from there if you add a new “Log Entry” it will create a new “log entry” with today’s date and the current time in it. Date and time are separate to ensure that the linking works automatically. So far though this isn’t any different than Brendan’s original “Link to Form” suggestion, it’s the same sort of flow.

    What is different about this is that if you create a new “log entry” record and make some changes to it, it will detect there isn’t a “day” record for itself and create one for you. I gave this a spin on my phone and it seems to work well and on the desktop it mostly works though sometimes I need to click the little “recalculate formulas” button if it doesn’t work.

    The script to make this work looks like this:

    var date = record.getFieldValue('fld-a415590fcdb649509e193c4eb473a966');
    var time = record.getFieldValue('fld-61ed0a92574d4fbc86448ce57a1d46bb');
    var symptoms = record.getFieldValue('fld-5c830b5a2499490d93726463d559d68d');
    var medications = record.getFieldValue('fld-233b18acd47645ad83c4721bb6ddb7b7');
    var pain_level = record.getFieldValue('fld-9221dc10702b40b498bc81cd6b96b907');
    var treatments = record.getFieldValue('fld-e31b6235845444b19dda6fe0acd8c2b3');
    var days_auto_link = record.getFieldValue('fld-a5fa3403ca284c809e353fc868b7b33d');
    
    var create = true;
    if (days_auto_link.length == 0 && date)
    {
    	var days = document.getFormNamed('Days').getRecords();
    	for(day in days)
    	{
    		var targetDate = days[day].getFieldValue('fld-fca7d2d982924a268353e8d24f8474c7');
    		
    		if (!targetDate)
    		{
    			console.log('Target date is invalid, skipping.');
    			continue;
    		}
    		
    		if (date.getTime() == targetDate.getTime())
    		{
    			console.log('Date equals target date, created already!');
    			create = false;
    			document.saveAllChanges();
    			break;
    		}
    		else
    		{
    			console.log(<code>Date comparison failed: ${date} != ${targetDate}</code>);
    		}
    		
    	}
    	
    	if (create)
    	{
    		console.log('Adding new form entry for today');
    		var newRecord = document.getFormNamed('Days').addNewRecord();
    		newRecord.setFieldValue('fld-fca7d2d982924a268353e8d24f8474c7', date);
    		document.saveAllChanges();
    	}	
    }
    else
    {
    	console.log('Autolink already exists. Tap Form users all shout hurray because in the JOIN we saved the day!');
    }
    

    The first stanza gets all of the fields in the form. This is necessary to ensure that Tap Forms triggers the script to do something as soon as something changes. There isn’t a way to hook into post-create with say a form script so this is the next best thing.

    It then sets a create flag to true to tell the system to create a new record, it checks to see if the JOIN field hasn’t already been set and if this record’s date field is unset (it should be autoset but it could be manually deleted). It falls into an else statement that assumes the date is correct and the form is linked with a fun little console message. Tap Forms is good about setting up the link as soon as the record is created in my limited testing so once a “Days” record exists already for the current day, it’ll autolink and save us a bunch of work.

    Assuming no link exists, the next step is to get all of the records in the Days form and iterate over them to look for a candidate date. This is probably overkill because we can probably rely upon Tap Forms validating this for us however I don’t mind being a little defensive here to validate if a record exists.

    In the loop we check to see if the date in the “Days” record is valid and if it isn’t, it continues to the next iteration of the loop. It then checks to see if it matches our “Date” field and if it does it disable the create flag and breaks the loop because we shouldn’t expect any other matches. There are some more console logs printed for validation because it never hurts.

    Once we exit the loop, we check the create variable to see if we should create a new record. If we need to create a new record, it creates a log entry, creates a new record and then sets the record’s date field to match this records date field and saves the changes. Originally I had this set up to just add the record and let the default value from the “Days” form set it automatically but then I realised this wouldn’t work if the record’s date was different to the current date.

    Attachments:
    You must be logged in to view attached files.
    #37172
    Brendan
    Keymaster

    You could write a script to copy data from one field into a Location field. But you should look at the structure of a Location field before you set the value of one. It’s a dictionary of keys and values: long, lat, and title. The title is the location address and long and lat are the longitude and latitude coordinates in decimal format.

    Brendan
    Keymaster

    Hi Marcus,

    1. In the next update I’ve added a function to let you get the record based on a record ID.

    form.getRecordWithId(record_id);

    It will be available in the next update.

    2. There’s no function for letting you add reminders for a date/time field. That’s all done right now through code in the user interface.

    3. No, there’s no function for formatting text in Note fields from JavaScript.

    Marcus
    Participant

    Hi Folks,
    after several days playing with scripts (I love it) I have 3 another questions:

    1. How to write in an existing recordset in another form ?

    Adding a recordset works:

    var doc=document.getFormNamed('Test2');
    var newRecord = doc.addNewRecord();

    I would like to modify an existing field in a known recordset (I have the ID of the recordset and the field).
    Additional: Would it be possible to search for a value and modify it in another form ?

    2. Is there a possibility to enable and customize a reminder in a date/time field ?

    3. is it possible to format text in a memo field (bold, font, size, color …) ?

    #37157
    Daniel Leu
    Participant

    From the documentation:

    Please note that the field IDs in the above script (e.g. movie_title_id = ‘fld-….’) are unique to the form this script was written for. You would need to use your own field IDs from your own form to make this script work.

    You create them inside the script editor by selecting the field and then clicking on the ID button.

    Brendan, it might be helpful to update the screen captures of the script editor as well to show all the buttons available right now.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #37147
    Brendan
    Keymaster

    Excellent suggestion. I probably wrote that script before I defaulted to appending “_id” to the field titles.

    I’ve just updated the manual.

    #37136
    Daniel Leu
    Participant

    Those are the field identifiers in your form. It would be better if the variable names in this example code ended with ‘_id’ as they do when you create them in the script editor,

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #37120
    patrick powell
    Participant

    Well, I get the theory of what you suggest (I think) but I have never tried my hand at javascript coding ever e.g. I haven’t a clue what an ‘array’ is. But I shall look into it tomorrow and follow the link Brendan gave for help with javascript coding. Thanks for the advice. P

    #37119
    Daniel Leu
    Participant

    I had a similar problem the other day. These are the steps I would use:

    1) Import your data into a form called “election results”.

    2) Create a second form called “constituencies”. Then create a form script that makes an array that contains each constituency only once. Using a javascript set object makes this very easy. Then have this script create new records in constituencies, one per constituency. Once done, you can delete this form as it is no longer needed.

    3) Link the two forms together using the ‘join’ link type on the constituency field. Now the two forms are linked. Enable Show Inverse Relationship.

    4) In the “constituencies” form, you now can do your analysis where you count the number of votes each party got etc. Thanks to the linked forms, you can easily loop over all matching records in the child form and add the votes per party. For this analysis you would have a bunch of record scripts that do the work for you.

    Hope this gives you an idea how this could be done. Happy coding!

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #37104
    Sam Moffatt
    Participant

    Check out the JavaScript API page: https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api

    If you have a named search then you can get that via form.getSearchNamed('Search Name') and then you can call getRecords() on what it returns to you.

    #37102
    Marcus
    Participant

    Ya, got it.
    I already created a bunch of helpful scripts,
    I only was stuck hanging to automate with a script field rather than execute it manually.

    One last question:
    Is there a possibility to get filtered recordsets only ?

    This returns ALL records:

    var records=form.getRecords();

    #37101
    Kenji Sugimoto
    Participant

    Daniel-san.
    Thank you for your code.
    I just wanted it.
    I will include the code in my scripts.
    Thank you again.

Viewing 15 results - 2,296 through 2,310 (of 2,950 total)