Permuting Variants Using Tap Forms

Viewing 3 reply threads
  • Author
    Posts
  • April 1, 2023 at 12:49 PM #49228

    smartin
    Participant

    Hello
    I’d like to generate a checklist that shows the universe of trading cards using Tap Forms.

    Typically card sets come in “Base” versions, then potentially have certain modifications known as “variants” … i.e. a different photograph or border design, etc.

    Downloading a checklist from the manufacturer you get the list of Base Cards; we’ll call this table A. You can also download another table of data that will show (as an example) if a certain Base Card has a short print, or a super short print, or an ultra short print variant; we’ll call this Table B!

    What we would like to do is connect Table A to Table B, and add a record to Table A if a short print variant exists in Table B. Heck, we’d add three records if a Card has all three variants of short prints. In that case we would have four unique records in Table A for the Base, Base SP, Base SSP, and a BASE USP variants.

    What is the best way to permute the baseline record in Table A to up to four unique records based on the information provided in Table B?

    Thanks for the help!

    April 2, 2023 at 6:06 PM #49250

    smartin
    Participant

    We gave it a try at coding and came up with what I will paste below. Unfortunately we’re getting a Syntax Error —> Permute_Short_Prints: SyntaxError: Unexpected end of script, line:78

    note: line 78 is the final line of the code.

    here’s the code. thanks to anyone looking it over and feeding back where we’ve gone wrong!

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    
    // Here goes nothing! We're going to try some Tap Forms Java to make a permutation of short print variants in our 2022 Topps Series One Form;
    // First we will define the Short Print field Id's from this Short Print Form with the following variable names using the const instruction;
    
    		const shortPrintId = form.getFieldNamed("Short Print").getId();
    		const superShortprintId = form.getFieldNamed("Super Short Print").getId();
    		const ultraShortprintId = form.getFieldNamed("Ultra Short Print").getId();
    
    // We'll call this script the Permute_Short_Print;
    // I don't know if this is where the function instruction should be placed, but here it is;
    
    function Permute_Short_Prints() {
    
    // These variables probably can (should?) be declared here outside of the search Loop (I think);
    // "2022 Topps Series 1" is another Form in the database with a full checklist of available cards (minus all of the permutations of variants);
    
    		const seriesOne = document.getFormNamed("2022 Topps Series 1");
    		let seriesOneRecord = seriesOne.addNewRecord();
    
    // Now we'll Loop over the fields in the Short Print Form. This script will be placed at the Short Print Form level using script button;
    		
    	for (field of form.getFields()){
    
    		// We'll define these variables inside of the Loop. Not sure if it has to happen this way, but seems right.
    			let seriesOneFieldId=seriesOne.getFieldNamed(field.name).getId();			let seriesOneShortPrintId=seriesOne.getFieldNamed("Short Print");
    			let shortPrint = getFieldValue(shortPrintId);
    			let superShortPrint = getFieldValue(superShortPrintId);
    			let ultraShortPrint = getFieldValue(ultraShortPrintId);
    				
    			// This one additional variable will be used to set a flag in the seriesOne Table to sort for scripted entries (in case we need that later)
    			let seriesOneScriptAutoEntryId=seriesOne.getFieldNamed("Script Auto Entry");
    				
    				
    		// IF NUMBER 1 -- This first If Statement will create a record in the seriesOne Form for short prints called "SP";
    				if (shortPrint = "SP") {
    				// true condition;
    					seriesOneRecord.setFieldValue(seriesOneFieldId, record.getFieldValue( field.getId()));
    					seriesOneRecord.setFieldValue(seriesOneShortPrintId, record.getFieldValue(shortPrint));
    					seriesOneRecord.setFieldValue(seriesOneScriptAutoEntryId, "Y");				} else {
    				// false condition is to just move on;
    					continue;
    				}
    	
    		// IF NUMBER 2 -- This second If Statement will create a record in the seriesOne Form for short prints called "SSP", or SUPER short prints;
    				if (superShortPrint = "SSP") {
    				// true condition;
    					seriesOneRecord.setFieldValue(seriesOneFieldId, record.getFieldValue( field.getId()));
    					seriesOneRecord.setFieldValue(seriesOneShortPrintId, record.getFieldValue(superShortPrint));
    					seriesOneRecord.setFieldValue(seriesOneScriptAutoEntryId, "Y");				} else {
    				// false condition is to just move on;
    					continue;
    				}
    	
    		// IF NUMBER 3 -- This third If Statement will create a record in the seriesOne Form for short prints called "USP", or ULTRA short prints;
    				if (superShortPrint = "USP") {
    				// true condition;
    					seriesOneRecord.setFieldValue(seriesOneFieldId, record.getFieldValue( field.getId()));
    					seriesOneRecord.setFieldValue(seriesOneShortPrintId, record.getFieldValue(ultraShortPrint));
    					seriesOneRecord.setFieldValue(seriesOneScriptAutoEntryId, "Y");				} else {
    				// false condition is to just move on;
    					continue;
    				}
    		
    		// save 
    		seriesOne.saveAllChanges();
    
    // ...and we are done!;
    
    }
    
    Permute_Short_Prints();
    

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    • This reply was modified 1 year, 1 month ago by Brendan. Reason: Added back-ticks to the code
    April 2, 2023 at 6:26 PM #49251

    smartin
    Participant

    ahhh… we figured out that we were missing a closing bracket ( i.e. a } )
    but we’re now getting a Reference Error –>Permute_Short_Prints: ReferenceError: Can’t find variable: getFieldValue, line:(null)

    Not sure how to diagnose this one. womp womp. Thanks to anyone who can help!

    April 2, 2023 at 8:13 PM #49252

    Daniel Leu
    Participant

    You have to provide a record object when using getFieldValue(). So that’s usually record.getFieldValue(fldId).

    BTW, if you encapsulate the code with back ticks (`), then it comes better readable.

Viewing 3 reply threads

You must be logged in to reply to this topic.