Scripting conditionals involving lists

Tagged: 

Viewing 3 reply threads
  • Author
    Posts
  • November 26, 2018 at 6:17 AM #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?

    November 26, 2018 at 7:02 AM #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.

    November 26, 2018 at 12:58 PM #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.
    November 26, 2018 at 6:04 PM #32139

    Kay Beckham
    Participant

    Edit: Never mind. Thank you for the sample script! And it works wonderfully!

Viewing 3 reply threads

You must be logged in to reply to this topic.