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 - 1,276 through 1,290 (of 2,989 total)
  • Author
    Search Results
  • #44644

    In reply to: Split note field?

    Sam Moffatt
    Participant

    On a similar note, I do something similar except the data I generally pull in is free form and I use a table field with a “Key” and “Value” fields inside it. It’s a similar sort of script except that you use fixed name for the key/value field names and an extra table field. There is an example of using a link to form/table fields and addNewRecordToField in the Get Movie Details from TheMovieDB API. If you know the keys are going to be unique, I also have a helper script on GitHub that scans a table field (also works with link to form fields) and expects a key/value field structure to then add only entries that are missing.

    #44641

    In reply to: Split note field?

    Brendan
    Keymaster

    Hi Emil,

    This can be done with a script.

    Here’s an example that takes the lines from a Note field and splits them into an array and then loops through the array of lines and writes each line to a separate field. I’ve made some assumptions here such as your field names have a pattern of “Field 1”, “Field 2”, “Field 3”, and so on.

    function Split_Note() {
    
    	var note_id = 'fld-c711358a858443c8805c8c98c71a03b4';
    	var note = record.getFieldValue(note_id);
    	var field_prefix = "Field ";
    	
    	if (note) {	
    		var lines = note.split("\n");
    		console.log(lines.length);
    		var fieldIndex = 1;
    		
    		for (line of lines) {
    			let field = form.getFieldNamed(field_prefix + fieldIndex);
    			if (field) {
    				console.log(field.name);
    				let field_id = field.getId();
    				record.setFieldValue(field_id, line);
    			}
    			fieldIndex++;
    		}
    	}
    	form.saveAllChanges();
    }
    
    Split_Note();

    You can see the result of running this script in my example screenshot.

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

    Topic: Split note field?

    in forum Script Talk
    Emil Mitchell
    Participant

    Dear all,

    I am rather new when it comes to technical database terms and I am hoping someone can help.

    I have a note field with approximately 5 lines of text. I have come to the conclusion that it would be better to have each piece of text within the note field within its own field.

    Is there a way to split the information within a field into separate fields using some technical scripting magic, rather than having to go back and edit them all manually?

    Thank you for your time!

    #44624
    Daniel Leu
    Participant

    Once you have your group of records using search, go to the multi-column view, set the first value and then click on the yellow dot and move it down. This will copy the value to the other fields.

    Another option would be a form script.

    Cheers, Daniel

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

    #44611
    JCK
    Participant

    Ohhhh kay. That makes sense. I realize now that I was calling the convertIMDBtoTMDB function at the wrong time.

    How do I add to a variable? Or is this something I’m confusing from coming from Shortcuts on iOS.

    The use case I’m running in to is for films with multiple directors. I’ve figured out how to loop through the results to get the names of both directors listed in the console, but I’ve run into a issue trying to add the positive results together.

    function getCrew() {
        var fullcredits = fetchCreditsFromURL();
        if (! fullcredits) {
            console.log("Request to get credits failed");
            return [];
        }
        return fullcredits.crew ? fullcredits.crew : [];
    }
    
    function getDirectors() {
         let crew = getCrew();
         for (let crewMember of crew) {
         			if (crewMember.job === 'Director') {
         				console.log(crewMember.name);
         				} continue; 
         		}
    }

    In Shortcuts, I would add an “Add to Variable” option, but there doesn’t seem to be anything like that in javascript. Adding a return function at any point seems to stop the loop, or only give the last result.

    Ideally I would like all positive results to be returned in a single string that I could add to a field. What am I doing wrong?

    #44608
    Redrock
    Participant

    Thanks much for all the info, Sam. I appreciate it. I didn’t realize TF scripts use java. I won’t tell you how long it’s been since I’ve coded, lol.

    As a former MS Access and HanDbase user, I vote for a TF enhancement to have the ability to create views where linked records can be created, edited, and displayed with their parent records—it’s a basic relational database function that could put TF at the head of the pack.

    #44603
    Sam Moffatt
    Participant

    First step is to check out the JavaScript API to get a feel for some of the stuff available.

    Next stop I’d suggest is to check out T.L. Ford’s JavaScript tutorials.

    If video is more your jive I’ve got a YouTube channel with some resources including a intro to scripting and a script field deep dive. There is also a video on link to form fields and scripting that might help as well.

    The forum has a bunch of great examples of how to use the scripting in Tap Forms. There was a recent post on using Markdown for contracts which leverages a script field to generate some Markdown output including leverage a table field. From a scripting perspective, link to form fields and table fields behave similarly so anything that works with a link to form field will work with a table field and vice versa.

    Hopefully this helps!

    #44602
    Redrock
    Participant

    Well, that explains why I couldn’t figure it out. I actually wanted to populate the linked form from the parent, in addition to simply displaying them.

    I tried using a table, but while it pulled over the child record names, there was no data.

    Scripts, huh? Sigh. Could you please point me to a reference guide?

    Thank you for the reply!

    #44601
    Brendan
    Keymaster

    Hi Redrock,

    There’s no custom layouts function on the iOS version of Tap Forms.

    And linked records always display in a separate list on iOS. At some point I might change that to display like the Table field does, which displays inline on the parent record as a table of sub-records.

    So if you need to display things visually like that, you would want to use a Table field instead of a Link to Form field.

    Or alternatively, you could write a script which picks out a field from the Link to Form field’s form and displays that in a list of values on the parent record.

    Thanks,

    Brendan

    #44595
    Sam Moffatt
    Participant

    You’re using a bunch of global variables, each time you do var thing then thing becomes a global variable when you’re doing it outside of a function. That’s why you can use the variables almost anywhere though in general that’s not best practice. The prompter uses this technique in part because it’s an async call but once we’ve stepped out of that, it’s best to use actual arguments and return values. When you do var inside the function, it’s scoped to the function and not accessible outside it. Let’s rewrite this slightly to use an input variable for inputID and return a value:

    function convertIMDBtoTMDB(inputID) {
        fetchURL = `
        https : // api.themoviedb.org/3/find/${inputID}?api_key=${tmdbAPI}&language=en-US&external_source=imdb_id`;
        var tmdbResp = Utils.getJsonFromUrl(fetchURL);
        var tmdbID = tmdbResp.movie_results[0].id;
        console.log(JSON.stringify(tmdbID))
        if (! tmdbID) {
            console.log("Request to get code failed");
            return "";
        } else {
            return tmdbID;
        }
    }
    

    Same function except we’re accepting an inputID as an argument and then returning the tmdbID. I left the tmdbAPI alone because I feel it’s a constant more than a variable and something you’d want to leave in global scope. Where possible you want to explicitly tell a function what it’s inputs are, in this case literally inputID but even in the other places it’s better to be explicit:

    function fetchCreditsFromURL(itemID) {
        fetchURL = `https://api.themoviedb.org/3/movie/${itemID}/credits?api_key=${tmdbAPI}&language=en-US`;
        return Utils.getJsonFromUrl(fetchURL);
    }

    That way you know where a variable is coming from and you’re less likely to have a variable in global scope accidentally trashed. Nothing in Javascript is straight forwards so I was looking for a good resource and this page on demystifying Javascript variable scope has some great details on how it works and where some of the pitfalls are.

    Instead of relying on the global changing, assign it to a variable in the right scope and then pass it along to anything else that needs it. Hopefully that helps get you a little further :)

    #44591

    In reply to: Shopping List

    robinsiebler
    Participant

    Ok, I added the checkmark field. In addition, I added a Search Filter for unchecked items and a script you can use to remove checked items.

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

    In reply to: Shopping List

    robinsiebler
    Participant

    SO just to verify:
    1. If you manually add an item to the Shopping List, the categopy is not added.
    2. If you manually run the script, the category is added.
    3. If you run the Shortcut the category is added.

    If all of that is true, I think all that I have to do is a add a field script to the Shopping List form that will update the category.

    I will try that and get back to you.

    #44584

    In reply to: Shopping List

    Roger Cuthbert
    Participant

    I added Naan manually and the shopping list record did not add the category.

    I created a shortcut as you suggested. Added Naan to the clipboard and ran your script and the category is added correctly.

    #44583

    In reply to: Shopping List

    robinsiebler
    Participant

    And the item you are adding is in the Product form and has a category? If so, could you try this? Add the item in question to the clipboard and just run the script ‘Get Item from Clipboard’. Let me know what happens.

    #44572

    In reply to: Shopping List

    robinsiebler
    Participant

    I fixed some bugs and added a notes field. I also added another 100 products to the products form. In addition, I updated the Shortcut to prompt for a note (see screen shot). However, Siri is stupid! If you say ‘No’ when you are prompted for a note, Siri bails on the entire script! So, instead of saying ‘No’, say ‘Later’ and you will not be prompted for the note.

    I should mention that you have to manually create the Shortcut using the attached screenshot as a guide. I have no clue how to share a shortcut outside of the Apple ecosystem.

    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 1,276 through 1,290 (of 2,989 total)