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,746 through 2,760 (of 3,049 total)
  • Author
    Search Results
  • #32114
    Federico Martinez
    Participant

    There are many ways to do this. first you need to specify which episode belongs to which trilogy in here I chose a table within the form because I think its just easy using the specified fields.

    After setting up pick list SS1
    and Setting up form with table SS2

    this code on script SS3:
    I am pretty new to tapforms and there maybe better ways to do this. also you need to replace the field value ID’s with the ones in your own script by pulling them from the available fields.

    // initial variables
    var episode = record.getFieldValue('fld-9e272cfa06144cfe94f46639cc4d651d');
    var table = record.getFieldValue('fld-fd2390f763264167809191f09badbbd2');
    
    //default no match variable in case it is not found.
    var result = "no match"
    
    // for loop to search for a match
    for (var index = 0, count = table.length; index < count; index++){
    
    // table variables
    var episodes = table[index].getFieldValue('fld-8b366549607a4664a2ad3cf9b77676f3');
    var trilogy = table[index].getFieldValue('fld-05603762b3ec47e19cedd2f0c1abc1a3');
    
    // if it finds match returns it.
    if (episodes == episode) {
    console.log(trilogy)
    	result = trilogy
    } else {
    	// false condition;
    }
    }
    result;

    you can hide the table in the form SS4

    Attachments:
    You must be logged in to view attached files.
    #32098
    Kay Beckham
    Participant

    To help save some time, I’ve attempted to write the code on my own by copying and pasting from other tutorials online.

    `var featured_series_id = ‘fld-1410861e610c4cba9abd7683e74d030d’;
    var StarWarsMovie = record.getFieldValue(featured_series_id);
    var StarWarsTrilogy;

    switch (StarWarsMovie)
    {
    case ‘Episode 1’:
    case ‘Episode 2’:
    case ‘Episode 3’:
    something something Prequel Trilogy
    break;
    case ‘Episode 4’:
    case ‘Episode 5’:
    case ‘Episode 6’:
    something something Original Trilogy
    break;
    case ‘Episode 7’:
    case ‘Episode 8’:
    something something New Trilogy
    break;

    So this is where it gets confusing. In the “Edit Field Script” window, I don’t see the option for the field that will run this script. I want the field to show those labels, but I’m kind of at a loss on how to make this happen.

    #32097
    Federico Martinez
    Participant
    var transfers = document.getFormNamed('Transfer requests');
    var pending_id = 'fld-ed603b4c67b14e829a2d96e5d3cab22c';
    var no_match_id = 'fld-7dcda80275e74246bf0bc3bcb5b6db86';
    
    var records = transfers.getRecords();
    
    for (var index = 0, count = records.length; index < count; index++){
      var pend = records[index].getFieldValue(pending_id);
    	
    	if (pend) {	
    	console.log("true");
    	records[index].setFieldValue(no_match_id, true);

    So this won’t execute a script on form “transfer requests”?
    is there a way to call on a script or formula to execute from another script?

    Thanks

    #32096
    Kay Beckham
    Participant

    Hello. I would like some scripting help with a database I’m creating.

    What I would like is to take the contents of a pick list, compare them with a different list (it can be within the script, or it can be referred from somewhere else, doesn’t matter), and then show the entry that matches the conditions. I’ve created a pick list in the preferences of my database.

    To use an example, the pick list has Star Wars Episode 1 to 8. The other list has three entries: Prequels, Original Trilogy, New Trilogy. So if Episode 2 is selected from the pick list, the Script field would show “Prequels”.

    Is this possible?

    #32071
    Ryan M
    Participant

    Thought I’d play around and see if I could come up with a different approach to the same mileage tracker. This would probably be closer to a fuel log rather than a simple mileage tracker.

    The inputs would be:

    – odometer value
    – Price per gallon
    – Gallons filled

    A script would calculate your mileage since last fill up as well as your miles per gallon.

    The script uses the default created date field to sort all records by their created date. This assumes that you’re entering in your mileage log around the time you filled up.

    Here’s the script for those interested

    
    var odometer_id = 'fld-9674e316bfed408ca6710ce81b72bf05';
    var vehicle_id = 'fld-64b0b17a635f49b8b40867e45f8d24db';
    var date_created_id = 'fld-2097149a2eeb4d4e892f13b62de6b5ea';
    
    // sort records in ascending order by date value
    var dateSorter = (a, b) => 
      a.getFieldValue(date_created_id) - b.getFieldValue(date_created_id)
      
    
    var run = () => {
      var vehicle = record.getFieldValue(vehicle_id);
      var odometer = record.getFieldValue(odometer_id);
    
      var records = form.getRecords()
        .filter(r =>  r.getFieldValue(vehicle_id) === vehicle)
        .sort(odometerSorter)
    
      var odometerValues = records.map(r => r.getFieldValue(odometer_id));
      var currentRecordIndex = odometerValues.indexOf(odometer);
      var previousRecordIndex = currentRecordIndex === 0 ? 0 : currentRecordIndex - 1
                     
      var mileageValue = odometerValues[currentRecordIndex] - odometerValues[previousRecordIndex]
    
      return mileageValue;
    }
    
    run();
    
    
    Attachments:
    You must be logged in to view attached files.
    #32065
    Brendan
    Keymaster

    Hi Federico,

    The scripts only get executed on the same form they’re referenced from. It happens when you call setFieldValue(field_id, value); I don’t traverse all of the linked fields to execute script fields on them.

    #32064
    Federico Martinez
    Participant

    if that field being edited is referenced. If so, then it executes that script.

    Hi Brendan,

    But this does not happen if it is edited from another script right? or at least not one in another form?

    right now I was trying to do scripts between 3 forms an independent scoring form, a capture form and a brain form that does what I need it to do. they all work great independently but to see the changes I have to wait until its done and then hit the refresh records for the other scripts to do their things. In my capture form its not a big deal but it is in my scoring form. I am taking advantage of the “link to form join” I can go around this by making more functions on the brain side and duplicating the other scripts. just wanted to make sure this is intended and not a bug.

    Thanks!!

    #31740
    Ron
    Participant

    It is a many to many. The script returns the correct value but when looking at the console log it gives the error.

    #31738
    Ron
    Participant

    After refreshing the record single column list the script field displays the correct result. The console log continues to display the same error.

    #31737
    Ron
    Participant

    Thanks for the example. I was able to adapt it to my form and when I run the script it returns the expected result, but it is not displayed in the script field on the layout. The console log returns this error:
    s_Doc: TypeError: undefined is not an object (evaluating ‘med_doctor[0].getFieldValue’), column:25, line:3
    s_Doc is the name of the script field.

    var med_doctor = record.getFieldValue('fld-84c907c7af3c49daa19ca1e30975bc1b');
    if(med_doctor){
    var Name = med_doctor[0].getFieldValue('fld-b1cfe8adec9b4d7397683b068a262cc2');
    Name;
    }

    med_doctor is the parent form and the var Name receives the correct value from the Name field of med_doctor.
    The error does not show in the script edit window when the run button is clicked, it only shows in the console if I click the save button and then open the log.

    #31733
    Ron
    Participant

    I have attempted to create a script field to return the value from a parent record without success. Could you please give a sample of your script.

    Thanks,
    Ron

    #31726
    Brendan
    Keymaster

    Hi Deborah,

    The reason this doesn’t work the way you would like it to is because a Join Link Type works basically the same way as a Many to Many. That is, you can actually have multiple parent records that all join to the same set of child records using the Join fields.

    So that means that a child cannot get access to just one parent record via the Calculation field.

    However, this is possible by using a Script field and having Tap Forms get the first parent record from the array of parent records and then picking out the value for the field from the parent record.

    #31692
    Brendan
    Keymaster

    Ah yes. The form.getFieldIds() method. I forgot about that.

    You’ll see the File Attachment fields in your form appear on the left panel on the Script editor after the next update.

    #31681
    Brendan
    Keymaster

    Well, it is still needed it seems. I’m not sure why yet. Because an NSArray in Objective-C is supposed to translate into a JavaScript array. But an NSDictionary just translates to a JavaScript Object, which I guess still needs to be stringified.

    #31671
    Daniel Leu
    Participant

    I was wondering how to get to the attachment ID…

    Following scriptlet shows the filename of the first attachment.

    
    var receipt_attachment_id = 'fld-8bbc0b1472a746cabc38f6d7ab045668';
    var receipt = record.getFieldValue(receipt_attachment_id);
    JSON.stringify(receipt);
    var meta = receipt[0];
    if (meta) {
    	meta.filename
    }
    

    Cheers, Daniel

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

Viewing 15 results - 2,746 through 2,760 (of 3,049 total)