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,281 through 2,295 (of 2,950 total)
  • Author
    Search Results
  • #37363
    Daniel Leu
    Participant

    I’m not certain that your comparison works. What is the content of fld-cf720b6ab4314f0bb5f47bc9bd61f0a9 supposed to be? The string ‘search’? Then it should be in quotes.

    Sidenode: I recommend to define all the fields used in a script at the beginning of a script or at the beginning of a function. And then use the identifiers later on. This increases readability, specially when you revisit a script that you wrote a while ago.

    var field_a_id = 'fld-....';
    var field_b_id = 'ld-....';
    ...
       if (rec.getFieldValue(field_a_id) == search) {
          // if match, do something
    	Utils.copyTextToClipboard(rec.getFieldValue(field_b_id));
          break;
       }
    ...
    

    Cheers, Daniel

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

    #37355
    David Gold
    Participant

    That’s strange. It started coming up for me as an app once I added my first Siri Shortcut. I see it in Shortcuts in the app list and when I click on it I see the scripts I have set up via Siri.

    #37345
    David Gold
    Participant

    On iOS if I add a Siri to a script and then create a Shortcut which runs that script as an action step is there any way to pass data either into the script or retrieve from the script? I can’t see anything on this in the API unless I’m missing it. If you can’t do this directly is there a workaround via the clipboard (ie can a script get information from the clipboard or can it at completion do that or display a result without having to launch Tap Forms)?

    #37344

    In reply to: record or records ?

    Sam Moffatt
    Participant

    Do you mind sharing a sample form demonstrating the problem? I’m not sure I quite follow.

    One though could be changing from var to let. var puts a variable in global scope whilst let isolates it to block scope. What is block scope? Any code at the same or lower level of brace. The Mozilla JavaScript reference on let has some details about use cases.

    There is also another caveat that sometimes Tap Forms will reuse a Javascript context.

    #37336
    Marcus
    Participant

    Hi,
    I am trying to figure out to limit a script execution for a list of records or for a currently open recordset.

    Behavior of the script below:
    When I open a table it works as expected.
    By opening a recordset of this table it works as expected as well.
    But when I go back to the list of recordsets
    the scripts assumes a recordset is still open.

    My script may be wrong, so my main question is how to detect if there‘s a list (recordsets) or a single recordset opened.

    Use case:
    I do have scripts accessing ALL recordsets
    and I do have scripts accessing only fields of the current opened recordset.
    I‘d like to prevent the execution in the wrong view.

    function check() {
       try {
          var res=record.getFieldValue('fld-76b2c64fccc34c20b62b7d485f5bfa28');
       } catch (err) {
          return 2;
       }
    }
    
    function myFunction() {
       Utils.alertWithMessage('Hello', 'Here I am !');
    }
    
    var tmp=check();
    if (tmp != 2){
       myFunction();
    } else {
       Utils.alertWithMessage('Notice', 'A recordset must be opened');
    }
    #37293
    David Gold
    Participant

    I’m not great with JavaScript but know some basics. I’m trying to write a script to search for a certain record (by searching a specific field) and when found return the contents of a separate specific field. Is anyone able to help?

    #37289
    Sam Moffatt
    Participant

    Ok so essentially you’re wanting to treat this like a bank account where each record is a line item that has a transaction value and then updates the balance from a starting point.

    Since you want to do per record storing that’s a little more nuanced, I’d actually go with a form script. I’m assuming you’re sorting records by something like date and what ever you’re using needs to be consistent. I’m going to assume this is ordered in a way that makes sense.

    Something like this should do the trick:

    function Calc_Balance() {
    	let balance = 3000000;
    	var amount_id = 'fld-454d9fcbfabd4e3fb89823668e042079';
    	var balance_id = 'fld-69d8d05d722f4dda9691dd687ed3b96c';
    	var transaction_date_id = 'fld-0ce56448807849699dfb2a22bb984774';
    	
    	for(record of form.getSearchNamed('Transaction Date: 1/10/19').getRecords())
    	{
    		balance -= record.getFieldValue(amount_id);
    		record.setFieldValue(balance_id, balance);
    	}
    	document.saveAllChanges();
    }
    
    Calc_Balance();
    

    The script is a little brute force which means it’ll rewrite everything but seems to work.

    Attaching a form template that has this script and an autogenerate script in it to generate sample data quickly.

    Attachments:
    You must be logged in to view attached files.
    #37280
    john cesta
    Participant

    OK I’m doing my best. I use your code Sam and it resolves but I don’t get a result anywhere.

    Here’s what I’m trying to do….
    I can win an apple watch if I write more than 3,000,000 of insurance volume before the end of the year,

    So I search for the policies I wrote between October and Dec 31 And have a total of volume.

    Now I want to, in each record, count down from the 3,000,000 to see where I’m at.

    So I reckon I need a form search to gather all the records that count and a record script to store the total of the search records in order to use the total to subtract from the 3,000,000

    #37277
    john cesta
    Participant

    In other words I want to run this script which totals the volume of only the selected records as in the image. But totals all the records in the form.

    function Volumecontest() {

    // Replace with your own code

    var volume_id = ‘fld-9b16cf5c9ee4420c83274f23ba59e554’;
    var total = form.getTotalOfField(volume_id);

    return total;

    }

    Volumecontest();

    Attachments:
    You must be logged in to view attached files.
    #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

Viewing 15 results - 2,281 through 2,295 (of 2,950 total)