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,216 through 1,230 (of 2,951 total)
  • Author
    Search Results
  • #44832

    In reply to: Linked Checkmarks

    Sam Moffatt
    Participant

    I did a checkbox flip flop thing a while back using scripting. Looking at that post, field ID’s are now available in the UI for fields so you don’t need to use the form logger to get the script field ID.

    It should be easy enough to copy and paste to handle the toggle properly. I did some updates for my toggle that also set a date field when my “confirmed” field is toggled and also reset the state if some other metadata is set that indicates that it should be in “confirmed” state.

    #44831

    In reply to: Checkbox Flip Flop

    Sam Moffatt
    Participant

    Update to this because I realised posting in another thread the OP here had a bug where newState wasn’t reset when toggling the corresponding checkbox. This should fix this and remove the form logger because you can now get the script field ID in the field list.

    Replace the field ID’s (e.g. fld-2adb9ba8cdd048bbbb614d46b415ada5) with the field ID’s from your form. The field ID is located under the description box for that field.

    // Import the logger and output the header.
    document.getFormNamed('Script Manager').runScriptNamed('Logger');
    logger.consoleHeader('Checkbox Flip Flop', 'Shipments');
    
    // Get the current values of the check boxes.
    var confirmed = record.getFieldValue('fld-2adb9ba8cdd048bbbb614d46b415ada5');
    var unverified = record.getFieldValue('fld-abdb319b7db74fc39812a94778c433cc');
    
    // Get the current value for this script field.
    var oldState = record.getFieldValue('fld-2cd0296ea0884c8cba3640d8e33f010b');
    
    // Create a copy of the new state for later.
    var newState = {'confirmed': confirmed, 'unverified': unverified};
    
    // For debugging, log the various states.
    logger.logMessage(`Current State: ${oldState}`);
    logger.logMessage('New State: ' + JSON.stringify(newState)); 
    
    // If we have an old state, we parse it out (otherwise it'd be null).
    if (oldState)
    {
    	oldState = JSON.parse(oldState);
    }
    else
    {
    	oldState = { 'unverified': false, 'confirmed': false };
    }
    
    // If the old state was unverified and not confirmed and this is confirmed...
    if (oldState['unverified'] && !oldState['confirmed'] && confirmed)
    {
    	// Update the unverified field to not be set.
    	logger.logMessage('Unsetting unverified flag since confirmed flag toggled');
    	record.setFieldValue('fld-abdb319b7db74fc39812a94778c433cc', false, false);
    	newState['unverified'] = false;
    }
    
    // If the old state was confirmed and not verified and this is now unverified...
    if (oldState['confirmed'] && !oldState['unverified'] && unverified)
    {
    	// Update the confirmed field to not be set.
    	logger.logMessage('Unsetting confirmed flag since verified flag toggled');
    	record.setFieldValue('fld-2adb9ba8cdd048bbbb614d46b415ada5', false, false);
    	newState['confirmed'] = false;
    }
    
    // Save the changes to the database.
    form.saveAllChanges();
    
    // Turn the newState into a JSON string.
    var result = JSON.stringify(newState);
    logger.consoleFooter('Checkbox Flip Flop', 'Shipments');
    
    // Return the JSON string for the next execution run.
    result;
    
    #44830
    Anthony Harrison
    Participant

    Hi
    Deep in my heart I know the answer is “Javascript” but does anybody know a way to link say, two checkboxes so if box “YES” is clicked then box “NO” can’t be? It is a visual thing for scrolling through records, I realise that an alternative would be Tick/No Tick but I prefer that a positive action is made.

    Many thanks if you can help.

    MiB
    Participant

    Hi Sam,
    since today, everything is working just fine. – Thanks to the tremendous help from Brendan.

    Here is what he has written:

    One, your info.txt files should have been UTF8 encoding, but they were MacOS Roman. Tap Forms assumes that it’s fetching UTF8 encoded data, so when it encountered MacOS Roman, the conversion from binary to a string returned a null value. When I changed your info.txt files to be all UTF8 encoding, then it worked.

    Two, the URL for the photo was not generated right. You were reading the photo filename from images.txt, but you were using that value as the URL.

    If someone has the same problem I have had after knowing this, here is a solution:
    I have over 800 info.txt files in over 800 subdirectories which are NOT UTF8 encoded.
    To get them converted in one go, use this line:

    find . -type f -iname “info.txt" -exec sh -c 'iconv -f MACROMAN -t utf-8 "$1" > converted && mv converted "$1"' -- "{}" \;

    I’ve used -iname because I have info.txt (lowercase “i”) and info.txt (uppercase “i”) files.
    “converted” is only temporary to overwrite the existing file. (Otherwise iconv would work like this: info.txt > info1.txt.

    The complete code and samples are in the zip file. (Already in UTF8)
    As mentioned above: You just have to change the username “mib” to your own in the Script and in the command file.

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

    Yup. That’s the solution to your export issue. I’m glad you found the script works for you. Because each form has a different set of fields and there needs to be the header row and there could also be a number of related records, it’s impossible to include the related records in the parent form. That’s why Tap Forms creates separate CSV files for each.

    But that’s also why I built the scripting engine to help with unique cases like this.

    Thanks!

    Brendan

    #44821

    In reply to: Gear check list

    Juha Ranta
    Participant

    Hi,

    I didn’t get to figuring out how to create the actual gear list from Tap Forms. But if anyone is interested in how I did export from that Skurka’s gear list to TaskPaper/OmniFocus, here’s what I did. I’m thinking of doing something similar if I get the TaskPaper gear list working.

    – I added my gear to the Google Sheets document, with some modifications.
    – Exported to a csv file.
    – Converted the list to a Taskpaper format with this quick Ruby script. It’s specific to the format that was in that Skurka page, but you get the idea.


    require "byebug"
    require "CSV"

    csv_file = ARGV[0]
    csv = CSV.new(File.new(csv_file)).read

    # Skip the header row.
    csv[1...].each do N|row|N
    # Skip the empty rows.
    next if row[0].nil?

    my_requirement = row[5]
    my_item = row[6]

    if row[1].nil? && row[2].nil? && row[3].nil?
    puts "\n#{row[0]}:"
    elsif !my_item.nil? || my_requirement == "Required"
    taskpaper_item = "\t- #{row[0]} - #{row[6]}"
    puts taskpaper_item
    end

    end

    Then I’m able to open the checklist while packing with MacOS TaskPaper. Or, since OmniFocus supports importing TaskPaper files, I can add it there as well. See the attachment.

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

    In reply to: Split note field?

    Sam Moffatt
    Participant

    Also uploading the archives. I need to get better at doing this as well.

    The TFF is a Tap Form Form Template, import it via File -> Import -> Form Template in a document. Form Templates are just the form definition, fields and form scripts without the data.

    The TFARC is a Tap Forms Archive, import it via File -> Import -> Tap Forms Archive in a document. A TFARC has all of the same data as the form template but also includes the records, in this case the sample data used in the example here.

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

    In reply to: Gear check list

    Sam Moffatt
    Participant

    Looking at the sample checklist I’d probably structure four forms:

    – Template: blue columns; the category heading (e.g. “footwear”) is another field. Add a checklist for “active”.
    – Hikes: hike metadata of when, where, etc that isn’t checklist related.
    – Checklist: green columns; the category heading (e.g. “footwear”) is another field.
    – Gear: simple form with your gear information normalised.

    Category heading is another field because it’s really a property of each row in that spreadsheet but we need to tell the computer that. Tap Forms has a spreadsheet like view, the multicolumn list view (MCLV), and you can use the grouping feature to recreate the column heading.

    I’d model Hikes as being linked to Checklist and Checklist having a link to Gear. You might want to add a “default gear” field to the template that can be used as well for stuff you almost always use (same sun glasses). From there I’d likely look at scripting to create a “hike” and then create new checklist records, linked to the hike, from the template records. I added the “active” field to the template so that you can use a saved search on active records when creating the checklist items. It allows you to have a template item that isn’t copied easily.

    On my YouTube channel, I have a <a href=
    https://www.youtube.com/watch?v=TB4EavvTihQ&list=PLyMabv86X9YFlGFdj5BWszcgYd9cSc-Jw”>playlist on building a meal planner which includes a shopping list that is built on the fly. Episode 3 introduces the shopping list and covers how to create “trips” with items from the list that haven’t been bought yet. A similar approach could be used where instead of a shopping list, it’s your template form and you create a hike from it and copy the entries over to the checklist. I made some tweaks in later episodes to the scripts for QOL but episode three demonstrates finding records, creating a new one and linking them together. The video on processing semistructured data into records also covers a use case where I’m copying data to create a new record though the focus parsing there.

    On the value replication for stuff like weight, you can use a calculation field to copy field values from parent of link to form 1:M though going the other way requires scripting to handle multiple values.

    Bit of a mind dump, hope this helps!

    #44810
    Juha Ranta
    Participant

    Hi,

    I’ve already made an inventory of my hiking, travel, trail running etc gear in Tap Forms. I like having the gear information, personal notes, weight, etc with me.

    Now, I’m trying to create something like this Andrew Skurka gear list for travel/hiking list. https://andrewskurka.com/backpacking-gear-list-template-checklist-3-season/

    I have the gear in Tap Forms already. I’ve been thinking of different options to create this kind of a gear list. In the end I’d like to export is as a Taskpaper/OmniFocus list.

    I did it this it this time by exporting from Tap Forms as CSV, then importing the items with their weight in Google Sheets. It was plenty of manual work.

    I wonder if there’s a good way to implement this kind of a system in Tap Forms. It would need:

    – Topics for things like
    – Utilities
    – Clothing
    – Food
    – Reference to select a tool from the gear list in Tap Forms
    – Way to calculate total count, maybe some more complicated calculations, such as in back / clothed on me
    – A default template that has the typical gear that’s with me for a backpacking hike for instance

    So I was thinking if this kind of a gear list system is easy to do with Tap Forms, or maybe I should export to csv, import to some spreadsheet software, etc. I work as a software engineer and can do scripting too with Ruby, Python, etc. I’m not just sure about what’s the best way to implement this kind of a thing at the moment, so I’d appreciate feedback. Thanks!

    Konrad Schoettl
    Participant

    No, there isn’t a circular reference as you described. I think I have found the reason for the crash. This occurs only with more than one ‘Link to Form’ field defined (in my case, there were two fields, each ‘many to many’). With only one such field, the export including the linked records works fine. But anyway, the export doesn’t work as I expected. I get several separated CSV files. But I wanted to get one file, containing also the linked records. For my book example, I wanted to export all books from the book form, including the author’s names from the author form. But the column for the author’s names (Link to Form) is empty.

    I found another solution for this purpose. I defined a script field in the book form that copies the author’s names into the book form. Now I can export the books with all author’s names into one file, what is what I wanted ?.

    Thanks
    Konrad

    #44803
    Daniel Leu
    Participant

    2 – If it isn’t in fact possible to search attachment fields, is there another way to do this?

    You can use a field script and use following code. This will return 0 if there are no photos and 1 if there is at least one photo. You just need to add the ID of your Picture field.

    function Has_Photo() {
    	let photo_id = 'fld-xxx';
    	let photo = record.getFieldValue(photo_id);
    	
    	if (photo.length > 0){
    		return 1;
    	} else {
    		return 0;
    	}
    }
    
    Has_Photo();

    Cheers, Daniel

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

    #44801
    Sam Moffatt
    Participant

    Maybe you could maker a timer/countdown app that supported x-callback-url and could be used in combination with scripting or URL fields in TF.

    #44775
    Kenneth James
    Participant

    Thank you. I knew of the distinction, and I even found my Java Script book to verify and all I was seeing were examples for the assignment designation – the single “=”. It just didn’t occur to me that that was the problem.

    Problem solved!

    Thank you
    KDJ

    #44770
    Kenneth James
    Participant

    I am misunderstanding something about how and when scripts are triggered and when they fire. My use case: Trying to set a toggle switch (CheckMark field) in a record that will populate a default value in the Location field, otherwise, just leave the Location field alone.

    The script in the Script Field.

    function Default_Location() {
    var useDefault = record.getFieldValue('fld-332bc0f45e1d4a9bbcf6b90d0087234e');
    
    console.log(useDefault) 
    	
    	if (useDefault = false) {
    		// the check mark is NOT checked meaning add the default location
    		record.setFieldValue('fld-e83fedb15a0d4a09be818513c2a0f4e5',
    			JSON.parse(

    {
    “altitude”: “849.74”,
    “heading”: “-0”,
    “lat”: “46.9999999”,
    “lon”: “-118.99999999”,
    “pitch”: 0,
    “title”: “123 Main Street, Anywhere, United States”}`))
    // my actual home address goes here!
    }
    }
    Default_Location();`

    What happens:

    Add a new record:
    CheckMark field = unchecked (i.e. false)
    Location field = blank (what it should be)

    While in the record, I check the CheckMark field indicating that the Location field should be auto-populated with the default value.
    CheckMark field = checked (i.e. true)
    Location field = still blank, nothing happens.

    Close the record and move to another record

    Go back to the previous record and re-open it.
    CheckMark field = checked (i.e. true)
    Location field = still blank, nothing happened.

    IF I REVERSE THE LOGIC IN THE SCRIPT, change the if (useDefault = true), THEN a new record is populated automatically with the default location while the CheckMark field is unchecked.

    Something is not behaving like I anticipate that it should be behaving.

    Obviously, I am missing something.

    Thanks for any advice.

    Kenneth James

    #44757
    Sam Moffatt
    Participant

    You can bulk import to the pick list or if you already have much of the structure defined you could use a form field as a source and import data into the form with a field per layer of your tree.

    Attaching a form template with up to 9 layers to show how scripting can be used to build it. Import the template, fill in some values and then in the pick list setting set it up with the use values from field option (see screenshot). As you do each layer, you can duplicate the record and update the value you need to change. Should make data entry a little less error prone. Trees are rather unwieldily to deal with unfortunately.

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