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 - 586 through 600 (of 2,989 total)
  • Author
    Search Results
  • #49325
    Paul Wirth
    Participant

    Hello again, I’m having an issue getting record.setNoteFieldValue() to work.

    (I mentioned this here but it wasn’t really on-topic, so I’m starting a new topic)

    Where targetId is the field ID of a Note field, using record.setFieldValue(targetId,'foo') updates the text of the Note field, but using record.setNoteFieldValue(targetId,'foo') fails to update.

    I’m attaching a Tap Forms document that demonstrates. One form uses record.setFieldValue() and the other uses record.setNoteFieldValue(). In each, the field script attempts to update a “Target” Note field based on text entered in the field “Trigger”.

    Attachments:
    You must be logged in to view attached files.
    #49315
    Paul Wirth
    Participant

    Too late to edit my previous post. I believe I found the issue:

    I’ve been editing my scripts in VSCode, and when a javascript line is beyond a certain length, either it (or the Prettier plugin) makes line breaks like this:

    const triggerFieldValue = record.getFieldValue(
      'fld-07c030d45e8642158be624403154874e'
    );

    When I edit the line in Tap Forms so that it reads all in one line, everything works.

    I’m guessing that Tap Forms is looking for a contiguous string like record.getFieldValue('fld-blablabla to set up the script trigger, and gets thrown off by line breaks.

    Not a huge deal, but perhaps that would be helpful to account for, for those of us who like to edit outside of Tap Forms?

    Edit: in the meantime, the Prettier plugin .prettierrc.js can be made to stop breaking long lines with:

    
    module.exports = {
      printWidth: 999, // Tap Forms script trigger expects <code>record.getFieldValue('fld-...)</code> to be all on a single line
    };
    

    Additional request: could you possibly account for variables in place of the actual field ID string, and still trigger a script? e.g.,:

    
    const triggerFieldId = 'fld-07c030d45e8642158be624403154874e';
    const triggerFieldValue = record.getFieldValue(triggerFieldId);
    
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    #49311
    Paul Wirth
    Participant

    Hi Brendan,

    Sorry, I didn’t explain well.

    Plan A — When I:
    – added a text field to the form
    – referenced that field in the script (record.getFieldValue...)
    – changed the value of that field

    The script didn’t trigger, including after restarting Tap Forms. I repeated this multiple times with new text fields

    Plan B — When I:
    – referenced a text field that had been there before introducing this script
    – changed the value of that field

    The script did trigger, consistently.

    The plot thickens, though: Since I’ve returned to Tap Forms, Plan B also doesn’t work. The script no longer triggers when the text field is altered.

    Here’s a basic script that repeats my issues:

    function changeTargetOnTrigger() {
    Utils.alertWithMessage('success!','the script was triggered');
    const triggerFieldValue = record.getFieldValue('fld-d5bbf5db0052462e8e138d1636718d64');
    const targetId = 'fld-a6c94d8bb94e4ee0a1287a046280a6d1';
    record.setFieldValue(targetId, triggerFieldValue);
    form.saveAllChanges();
    }
    changeTargetOnTrigger();

    I’m attaching a minimal document that includes the script and relevant fields (Basically just a form with three fields: “Target”, “Trigger”, and “Script”.

    When running the script manually, the value of the field “Trigger” is applied to the field “Target”. But when changing the value of the field “Trigger”, the script doesn’t run. Maybe I’m missing something obvious!

    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    • This reply was modified 2 years, 9 months ago by Paul Wirth.
    #49310
    Victor Warner
    Participant

    Brendan,

    Thank you. Issue resolved.

    I would like to add one addition to number the combined values, e.g. “1. certificate of good standing, 2. Power of attorney, 3. statutory declaration, 4. travel consent document” with the following field script:

    function recordsLoop() {
    
    var all_documents_id = 'fld-b130f329a7ae46f3908d190699822044';
    var script_id = 'fld-bb67d87c0f044b2cb2745ba9e3fde81f';
    
    	var forms_id = 'fld-8c147256f1534336aa960e509a8b826b';
    	var name_of_document_id = 'fld-03b7ec42c07542ea8cfc23d4809ef367';
    	var forms = record.getFieldValue(forms_id);
    
    	var allDocs = [];
    	
    	for (var index = 0, count = forms.length; index < count; index++){
         	var name_of_document = forms[index].getFieldValue(name_of_document_id);
    		if (name_of_document) {
    			allDocs.push((index+1) + ". " + name_of_document);
    			
    		}
    	}
    	
    return joinedDocs = allDocs.join(", ");
    
    console.log(joinedDocs);	
    
    }
    
    recordsLoop();
    

    However, where there is only one value I would like that single value not to have a value, e.g. rather than “1. power of attorney” but rather just “power of attorney”.

    How can the code be amended to permit this?

    #49307
    Brendan
    Keymaster

    Hi Paul,

    Tap Forms will only run the script if the field already exists in the form. That’s normal behaviour.

    Try quitting Tap Forms and launching it again to see if script triggering works properly when you change a value in the referenced field.

    #49302
    Paul Wirth
    Participant

    I think this is probably a bug.

    I was attempting to get changes in a field to trigger a field script, using a reference to record.getFieldValue('fld-blablablabla') in the script. The script would only trigger when the field referenced was one that had already existed in the form (in this case, a text field that I wasn’t using). If I created a new text field, referencing the new field’s ID would never cause the script to be triggered when that new field’s value was changed.

    In the end, I went through the trouble of creating a script to copy all data from the field that worked correctly as a trigger, to a new field, just so I could use old field properly as a script trigger.

    #49299
    Brendan
    Keymaster

    Hi Victor,

    On the Script Editor, if you select a field from your Link to Form field and then double-click on the “Child Records Loop” code Snippet, Tap Forms will write the code for you to loop through all your child records, extracting out the value from the selected field.

    Now you can use the JavaScript push() function to combine all the values from that field into an Array. Then after the loop, use the JavaScript join() function to join them together with a comma separator.

    Then use the Tap Forms Utils.copyTextToClipboard() function to copy the value to the clipboard.

    Then set the value on the field in your Form 1 using record.setFieldValue(field_id, joinedDocs);

    Here’s a start for you:

    function recordsLoop() {
    
    	var forms_id = 'fld-8c147256f1534336aa960e509a8b826b';
    	var name_of_document_id = 'fld-03b7ec42c07542ea8cfc23d4809ef367';
    	var forms = record.getFieldValue(forms_id);
    
    	var allDocs = [];
    	
    	for (var index = 0, count = forms.length; index < count; index++){
         	var name_of_document = forms[index].getFieldValue(name_of_document_id);
    		if (name_of_document) {
    			allDocs.push(name_of_document);
    			
    		}
    	}
    	
    	var joinedDocs = allDocs.join(",\r");
    
    	
    	return joinedDocs;
    }
    
    recordsLoop();

    It literally took 30 seconds because Tap Forms did most of the work for me writing all that code just by double-clicking the Child Records Loop snippet. All I did was defined the allDocs array, then pushed the name_of_document value to the array inside the loop. Then joined and returned the joined value.

    Victor Warner
    Participant

    I would like to make a script that takes the content of a field from linked records of another form and combine them together.

    For example, see attached Tap Form database

    In Form 1 there is a link to Form 2

    So I would like to create a script which:

    1. combines the fields for the 4 linked records
    2. combines them together with commas after each but adds numbers before each field (eg “1. certificate of good standing, 2. Power of attorney, 3. statutory declaration, 4. travel consent document’)
    3. copies the result to clipboard and writes the combined fields into the All documents field in Form 1

    Help on how to do this would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    #49285
    Charlie
    Participant

    Thanks Daniel.

    It’s almost there. I have some duplicates of similar names. Like ljud: Ljud, Ljus: ljus, kamera… etc. Alson i have checkmarkfield ”inkommen” marked true or false. I wonder how to, not have ”inkommen”, true in the mail. Signature is jpeg file that the script cant translate. Small issues could be big script problems. Any way Happy easter.

    #49260
    Charlie
    Participant

    Hi Daniel

    Thanks for your support. I got the name and all the field that is not linked to other forms to be copied to mail. That’s great. I also tried to test to change field 32. But i don’t get info from other forms. Like ”kameror”, ”ljud”, ”grip” and so on. I am useless to script writing Thanks for your time and work.

    #49259
    Daniel Leu
    Participant

    Hi Charlie,

    Thank you for the form. I’ve enhanced the script a bit to process date fields as such, include the name field from the contact, and to report child records as well. Please note that I only did some minimal testing.

    I have updated the script over on https://lab.danielleu.com/blog/sending-record-by-email/

    Your top-form contains links from other forms and not to other forms! You will need to update line 32 from } else if (f.fieldType == "form") { to } else if (f.fieldType == "from-form") {.

    Cheers, Daniel

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

    #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 2 years, 9 months ago by Brendan. Reason: Added back-ticks to the code
    #49245
    Ronald Kroeker
    Participant

    Daniel, Thanks for your patience.
    You were correct I had a typo 😔…I had written
    “CONCAT((Date[Date];yyyy-MMM-dd);[Name field])”
    I had bracket in wrong order and forgot quotes.
    Thanks again for the assistance.
    P.S. What is the correct formatting for long date?
    You had used yyyy-MMM-dd but would like to display full date? Haven’t ventured into scripting yet but will once I have finished my transition with tapforms.

    #49227
    Charlie
    Participant

    Daniel Thanks for the script. I have linked fields that don’t show up as they do on the computer. Even if i make a pdf the field don’t show the linked form. So at the moment i’m stuck. But thanks for support Daniel

    #49203
    Daniel Leu
    Participant

    Yeah, you could write a script or use the calculation field to strip “A “, “An “, or “The ” from the title string. The script or calculation would then return the shortened title on which you could perform your search.

    Using calculation seems to be a bit more complicated than using a script:

    function Stripped_Title() {
    	// Define Id of title field
    	const title_id = 'fld-dec6b20e27d343e181e37a813624b467';
    	let title = record.getFieldValue(title_id);
    
    	// Check for "A "
    	if (title.toLowerCase().substr(0,2) == "a "){
    		return title.substr(2)
    	}	
    
    	// Check for "An "
    	if (title.toLowerCase().substr(0,3) == "an "){
    		return title.substr(3)
    	}	
    	
    	// Check for "The "
    	if (title.toLowerCase().substr(0,4) == "the "){
    		return title.substr(4)
    	}
    }
    
    Stripped_Title();
    

    I don’t know if all your titles start with an uppercase character. So I translate them to lowercase to catch “a”, “an” and “the” as well. Good luck!

    • This reply was modified 2 years, 10 months ago by Daniel Leu.

    Cheers, Daniel

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

Viewing 15 results - 586 through 600 (of 2,989 total)