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,326 through 2,340 (of 2,986 total)
  • Author
    Search Results
  • #37271
    Daniel Leu
    Participant

    Yes. If the search is already active you can use var records = search.getRecords();. If you want to run a specific search from your script, use var records = form.getSearchNamed('search name').getRecords();.

    Cheers, Daniel

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

    #37267
    john cesta
    Participant

    Is there a way to run a script on just a search selection of records?

    Thanks

    #37256
    ct4
    Participant

    Just a more detailed description on what is happening. If I open document 1 (the one I want to open on startup) and leave it open when I quit, then when I start, Document 2 (the one I don’t want) opens.

    If I have no document open on quitting, then no document opens.

    #37219
    Matthew Johnson
    Participant

    Daniel, That’s amazing!

    Daniel,
    Thank you!
    I’m amazed how quickly you just whipped that up!

    I got interest from my 6 year old daughter to catalog her books… but she was discouraged by how much time it would take to type it all in. She was excited to see your script in action this morning! Seeing this script in action gave me an idea to take it a step further and make it a one of a kind tool that could help educators.

    Now let me ask this… Many elementary schools in the US in order to classify books based on it’s reader’s ability to read and their known vocabulary, are identified by it’s “AR level”. The company that started this is called Accelerated Reader. They have a website to enter info about the book,
    ARbookfind link
    and it will tell you what it’s “AR number” is. From reading up on this a bit… this platform does not have an API, and the site uses cookies, so from what i’ve been reading this is a big problem… but I’m not as savvy on the scripting and programming side of things as I wish I were. If someone could add to Daniel’s script a field that provides the “AR level” number, this app could be extremely useful to almost any elementary school teacher, as well as Librarians in the US.

    Being able to Print out Labels with the AR Level on them would be a huge win for teachers… so If anyone is willing to take a poke at this and can get it working… I’ll gladly share this with with the teachers at the school I work at. I can get instant feedback from them as well. Many use alternative database software to check books out of their rooms to students to take home… but none of them have a built in AR level field… so Tapforms I believe would be the first to have that… and when Teachers find useful tools they show them to their colleagues.

    I love this community that Brendan set up for us. This has been exteremely helpful.
    Thanks again Daniel!

    #37216
    Sam Moffatt
    Participant

    You can’t use a calculation field on Link to Form fields when the field could have multiple records contained within it. This is why you’re seeing the aggregation functions being used. If you are on the other side of a 1:M, then you can include values because there is only one ancestor however every other type and direction could have multiple values that need to be aggregated.

    A script field has a more control over what you can do at the cost of more coding, it should do what you need to achieve.

    #37210
    Daniel Leu
    Participant

    This was a fun little project. It looks like the ISBN record is not the same for all books. Specially foreign books. So maybe there are other foreign reverse ISBN services that provide better infos.

    var isbn_id = 'fld-274d1f7125404b6fb066fab21f67f834';
    var title_id = 'fld-f46fd341844849b1ad91d8c20712cefb';
    var subtitle_id = 'fld-cb24da764ce644bea8a24decef8146ce';
    var author_id = 'fld-67a6fcecfce945d0ba16fcb5b5e63001';
    var published_date_id = 'fld-672306e2df2f42488e2d1975df1de3e3';
    var url_id = 'fld-aaa8aa064e43416f80318a0a9e3a2470';
    var thumbnail_url_id = 'fld-8eeba1cd75c84555a51fe7f0dd273dcf';
    var description_id = 'fld-23b3241169fb41829b4cc26852dae873';
    var thumbnail_id = 'fld-41d3474969ba4a21ae5360148cf5444b';
    
    function fetchProductInfo(isbn) {
    	var url = 'https://www.googleapis.com/books/v1/volumes?q=isbn:' + isbn + '&format=json';
    	var product_info = Utils.getJsonFromUrl(url);
    	return product_info;
    }
    
    function Get_Isbn(isbn) {
    
    	var info = fetchProductInfo(isbn);
    	
    	// there should be only one book
    	if (info['totalItems'] == 1){
    		var book_info = info['items'][0]['volumeInfo'];
    		
    		//console.log(JSON.stringify(book_info, null, 2));
    				
    		record.setFieldValue(title_id, book_info['title']);
    		record.setFieldValue(subtitle_id, book_info['subtitle']);
    		var authors = book_info['authors'].join(', ');
    		record.setFieldValue(author_id, authors);
    		record.setFieldValue(published_date_id, book_info['publishedDate']);
    		record.setFieldValue(url_id, book_info['canonicalVolumeLink']);
    		record.setFieldValue(thumbnail_url_id, book_info['imageLinks']['thumbnail']);
    		record.setFieldValue(description_id, book_info['description']);
    		record.addPhotoFromUrlToField(book_info['imageLinks']['thumbnail'],thumbnail_id);
    		document.saveAllChanges();
    
    	} else {
    		Utils.alertWithMessage("Get_Isbn", "Fetched " + info['totalItems'] + " instead of 1. Aborting");
    	}
    	
    }
    
    Get_Isbn(record.getFieldValue(isbn_id));

    Attached is the template.

    Attachments:
    You must be logged in to view attached files.

    Cheers, Daniel

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

    #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.

Viewing 15 results - 2,326 through 2,340 (of 2,986 total)