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,246 through 1,260 (of 2,989 total)
  • Author
    Search Results
  • #44873

    In reply to: Link to dates in form

    Brendan
    Keymaster

    I wonder if a Table field would be ideal for this sort of thing?

    Do you mean that if you change a date on the Parent record, all the linked records would have their dates updated? So if the parent field had a Project Start Date and the Table field had a Task Start Date, if you change the Project Start Date to something later, the Task Start Date for each task would also change?

    If so, then a Script field would certainly be able to do this. Just loop through all the Table field records and update the Task Start Date depending on the Project Start Date.

    I don’t know if it would be all that difficult. And doesn’t use a Linked form, although a Table field is similar to a Link to Form field in the way it displays. It just doesn’t have a separate form for it. The sub-fields are all configured on the Table field itself.

    But maybe I’m misunderstanding the requirement.

    Thanks,

    Brendan

    #44870

    In reply to: Link to dates in form

    Sam Moffatt
    Participant

    I don’t think there is an easy way to do this, or even a hard way for that matter.

    The feature you’d need is self linking forms and whilst it sort of works, it only does so for M:M links when for this you’re building a tree like structure that would be 1:M. I got something sort of working with two link to form fields but it was janky and didn’t quite work the way I’d like and would still put the parent record in the child section. That would mean a second form to store the links and likely a bunch of scripting to replicate the TF record picker. Not impossible and with a lot of work, you could build the linking infrastructure you’d need to make it work and then once you’ve got that a moderately complex script field could push the update.

    #44868

    In reply to: what is wrong

    Sam Moffatt
    Participant

    As a script it’d be something like this:

    function Flag() {
        var classtype = record.getFieldValue("fld-fieldid1");
        var yps = record.getFieldValue("fld-fieldid2");
    
        return (classtype == "Std" && yps > 3.64) ? "" : "?";
    
    }
    
    return Flag();
    

    Note: class is a reserved word in Javascript so not a valid variable name.

    The fld-fieldid1 is the ID of the field, the script editor can help you generate a line for that (double click field on desktop or on mobile there is a field picker) with the variable name and field ID preset. You can also get the field ID from the form editor when you select the field to splice in the ID yourself.

    You don’t need the full function wrapper but I find it feels more natural to do the return statement. The return is using a ternary operator to do the comparison compactly.

    #44866

    In reply to: what is wrong

    Tim Flick
    Participant

    What this same calculated field look like in a script Thanks much

    #44864

    In reply to: Display GrappObject

    Sam Moffatt
    Participant

    Script field is Javascript so anything you can code into Javascript you can put as a condition. It’s a bit more verbose than the calculation fields but I feel a lot more flexible and expressive plus the development loop is a little easier as you can run it inside the editor and see the result (or get an error on the console from the JS interpreter).

    For each field, you need to do a record.getFieldValue to grab the value and then you can do what ever operation you need (obviously limited by Javascript).

    #44852

    In reply to: Display GrappObject

    Sam Moffatt
    Participant

    On the emoji front, I went looking for something that could automatically take the country and turn it into a flag, I found some sample code that used the country code to turn into the flag. I pulled that into a script and it seemed to work out ok:

    function getFlagEmoji(countryCode) {
      return countryCode.toUpperCase().replace(/./g, char => 
          String.fromCodePoint(127397 + char.charCodeAt())
      );
    }
    
    function Flag() {
    	var country = record.getFieldValue('fld-7769fdcb2a4f46a8a225db562a289359');
    	return getFlagEmoji(country);
    }
    
    Flag();
    

    Replace the field ID with your field ID, if you want to do some extra translations or mappings then you can do that in script but if you do some data wrangling this won’t be too bad. I grabbed the country code list from W3Schools and pasted it into a new form with the above script via the MCLV and it’s attached below as a Tap Forms Archive.

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

    In reply to: Display GrappObject

    Brendan
    Keymaster

    Hi Tim,

    You could maybe do something like that in a Script, but use Emoji’s for the flag instead of a graphic object. Although I guess depending on what you’re trying to do, just a Calculation field that looks at a value from a field and returns an Emoji flag character depending on the result.

    Something like:

    IFEQUAL(Country; "Canada"; "??"; "")

    So this says, if the value of the Country field is “Canada”, return the Canadian Flag emoji, otherwise, return nothing.

    Thanks,

    Brendan

    #44841
    Kimberley Hoffman
    Participant

    I am going to pick up where I left off. Book number four is at the printers and I am thinking of how to organise the fifth one using Tap Forms. Book number three has been long-listed for the world illustration awards. :)

    Since the file I use for keeping track of my participants works – it is a separate file not connected to any client based files – I was wondering if there were any way to link to the client based file?

    I’ve been giving this some thought. I only need a project file as long as the project is active. After that I prefer to retire it out of view.

    Things that I need for my project file from the client based file would be client, client contact details, client number.

    I would also need to add contact details of people that are involved with the project, but who are not the client. This could include city marketing companies or tourism associations, for example.

    Would it make more sense to just create a field to link other files, separate from the project, as you would with documents or structure it so that the all the files are linked?

    One note here: The participant files are always completely separate documents from the client files.

    I need some room to think out loud now and hopefully get some logical feedback, whilst my mind springs from tree to tree

    Ideally for the project file I would have three forms:
    1. The project detail form

      Project name
      Project number (which is dependent on the client’s number – which is why I really would like to connect it to the client & acquisition file or visa-versa)
      Work hours and details imported from a csv-file (I use Tyme2, which has proven to be very good for me)
      Time planning, like as in a Gant-Chart (page 1 needs to be done by this date, page 2 by then, etc)
      Project description
      Information about repetive characters including a brief description and linked turn-around drawings
      An additional contact list of people involved in the project

    Client information
    Support information (people who are important to talk to, places to draw about)

    2. The participant form
    This form contains cvs-data imported from my newsletter provider
    I might need to add the details (names, ages, addresses if different from the person who organised the participation) to the form. these aren’t contained in the original registration. Germany is very strict about data collection. This would have to be manually added.
    I also use this form to provide the press with statistics. Therefore, I do not wish to create separate entries for people in the groups and family type categories. That would skew everything. This time around I duplicated the entry, changed the number of participants to “0” and put in the address of the person/people pre-ordering books.I use the filter to filter out the number of books pre-ordered so that I can send that information to the publisher to process.

    3. Book pre-orders
    This should populate from the participant form, however as I just experienced this week, people who are in groups pre-order for themselves and aren’t listed personally in the participant form. I can only find them by searching the email registration and the documents submitted. Their addresses are not listed and the books would be billed and delivered to the wrong address otherwise.

    Does anyone see any holes in this? I would appreciate any feedback before I set up the next file. Thanks
    Regards,
    Kimberley

    #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.
Viewing 15 results - 1,246 through 1,260 (of 2,989 total)