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 - 211 through 225 (of 2,950 total)
  • Author
    Search Results
  • #51573
    Tap forms Forum
    Participant

    I’m trying to write a script that adds a pdf to a file attachment field, but addFileFromUrlToField consistently crashes Tap Forms (at least on iPadOS 18.2.1).
    Here’s an example with the Tap Forms manual:

    function Test_Pdf() {
    	// Field ID
    		var file_attachment_id = 'fld-858558a7165649e6ac3bd117e17483ec';
    	// file url
    		var url = "https://cdn.manula.com/user/1444/1328_16794_en_1538683502.pdf?v=20240123105634"
    	// add new record
    		var newRecord = form.addNewRecord();
    	// add to field
    		newRecord.addFileFromUrlToField(url, file_attachment_id)
    }
    
    Test_Pdf();
    document.saveAllChanges();

    This script does create a new record, but then crashes when it tries to add the pdf. I’ve tried different files and even images that do work when using addPhotoFromUrlToField to a photo field, but Tap Forms always crashes.
    Is there something special I should do to the file object before adding, or is this a bug?

    #51571
    Daniel Leu
    Participant

    What you could do is using a field script that combines all table data into one field. Then when you export your form, such data would be included.

    Here’s an example of such a field script. You need to replace ‘fld-xxx’ with the field id of your table.

    function Table_Text() {
    
    	// set field value according to your form
    	const table_id = 'fld-xxx';
    
    	// get table records
    	let tableRecs = record.getFieldValue(table_id);
    	
    	// extract all table values
    	let tableValues = [];
    	tableRecs.forEach( (a) => {tableValues.push(a.values)});
    	
    	//console.log("Raw data:\n"+JSON.stringify(tableValues,"",4));
    	
    	// extract all table values
    	let tableText = [];
    	for (tableValue of tableValues){
    		let row = [];
    		for (const [key, value] of Object.entries(tableValue)) {
    			row.push(value);
    		}
    		tableText.push(row.reverse().join(", "));
    	}
    	
    	//console.log("Extracted data:\n"+tableText.join("\n"));
    	return tableText.join("\n");	
    }
    
    Table_Text();
    

    Cheers, Daniel

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

    #51538
    Brendan
    Keymaster

    I’m glad you found the Scripting documentation. Form scripts are activated only when you manually run them. Field scripts are activated when a field you’re getting the value from is modified within the selected record. Creating a Form script automatically attaches it to the selected form.

    #51531

    In reply to: Button to open media

    JScottA
    Participant

    The following is from the Tap Forms Assistant, an unofficial custom GPT. Maybe it can help you:

    To implement a button in your Tap Forms “Pretty View” layout that opens the first attachment in the “Video” field, follow these steps:

    1. Prepare the Field
    • Ensure your “Video” field is a “File Attachment” field. If it supports multiple files, you should confirm this by checking if “Multi-File Enabled” is selected in the field’s properties.

    2. Create or Edit the Layout
    • Navigate to the Layout Designer by selecting the desired form and choosing the Layouts tab.
    • Either create a new layout or edit an existing one.

    3. Add a Button to the Layout
    • Drag a “Button” field from the Layout Designer’s tools panel onto your layout.
    • Position it wherever you’d like it to appear in the “Pretty View.”

    4. Configure the Button Action
    • Assign the button an action to execute a script. Scripts in Tap Forms use JavaScript, which allows you to access and manipulate your database.

    5. Script to Open the First Attachment

    Use the Tap Forms JavaScript API to implement the button’s functionality. Here’s an example of a script:

    // Assuming the field name is “Video”
    var videoFieldName = “Video”;
    var videoField = record.getFieldValue(videoFieldName);

    if (videoField && videoField.length > 0) {
    // Open the first attachment
    var firstAttachment = videoField[0];
    document.showFile(firstAttachment);
    } else {
    document.alert(“No video attached to this record.”);
    }

    This script:
    • Retrieves the attachments from the “Video” field.
    • Opens the first attachment using the document.showFile() method.

    6. Test the Layout
    • Save the layout and test the button to ensure it opens the video as expected.

    For more detailed guidance on layouts and scripting, you can refer to the Tap Forms documentation on Layouts (Page 80) and JavaScript API (Page 58) in the manual .

    If you encounter any issues or need further clarification, let me know!

    #51521
    Keith Tizzard
    Participant

    I have just created my first application in Tap Forms. Works well and was simple to create.

    I now want to explore Scripting but need a few pointers to where to start. I can see the panel on the right of the Form screen with 3 tabs Form, Fields, Scripts.

    Clearly I need to create a new Script in the Scripts tab.

    Questions:
    1 how do you attach a Script to a Form?
    2 How do you attach a Script to a Field?
    3 In each case when is the Script activated?

    Can your please direct me to the documentation that explains this.

    #51517
    Brendan
    Keymaster

    Hi Jeff,

    With a Join relationship, both sides of the relationship are “many” relationships. That means both sides, the parent and the child, can have many records.

    In the Invoices form, there can be only one parent for a child record, so the Link From Form field can be used to directly get a parent record’s value to display on the child. With a Join or Many to Many, you need to use a Script field, get the first parent record, then get the values for the fields you’re interested in.

    A Link From Form field is created automatically for you on the child form (the form you’re linking TO) when you enable the “Show Inverse Relationship” option.

    So basically you need a script that fetches the records from the parent, creates the value you want to display, and returns it.

    Thanks,

    Brendan

    #51496
    Brendan
    Keymaster

    Hi Jeff,

    You could do this with a Form Script. But it would take some time and thought into exactly how you want it to work.

    But certainly a script can copy values from one form, create a record in another form and then set those values into the record in the other form.

    I don’t have time to write the script for you though, but you could look at the scripting information here:

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    And the Scripting 101 tutorial by TL Ford, which is linked from my support page:

    Support

    Thanks,

    Brendan

    #51492
    JScottA
    Participant

    If it helps, there is an unofficial custom GPT on the ChatGPT store called, Tap Forms 5 Assistant that is tuned specifically for scripts in TF5. Here is the link:

    Tap Forms 5 Assistant

    I hope that it helps you. However, Brendan is the final authority on all things TF5.

    #51491
    Sarah Young
    Participant

    That is very helpful, thank you Brendan! It’s a 1:M relationship, so will need a script.

    I’ve also now found the javascript documentation which I think/hope will get me the rest of the way there. (somehow I missed this yesterday when I was looking for info, so apologies for asking a question that is probably in those docs!)

    #51487
    Robert Reheis
    Participant

    Howdy :-).
    Apologies for a probably stupid question but I was not able to find a description in the Manual.
    I’ve got a TapForms v5 DB on my MAC; added a) a coloured Form for entry and maintenance and using b) the chart / graph view.
    Now – downloaded Tap Forms on iPad and synced via iCloud – all data being synced and ok; however, I am missing my own created coloured form.
    What do I have to do to get it synced as well?

    Many thanks in advance.
    Robert

    #51484
    Brendan
    Keymaster

    What kind of relationship do you have between the parent and child? If it’s a Join relationship, then when you add a Child Record, Tap Forms should automatically set the value from the parent to the child’s matching field value.

    But if that’s not what you want, then you would need to use a script to create a child record, add it to the parent’s Link to Form field and copy the value from the parent to the child field.

    You would use the addNewRecordToField() function for that:

    var parentRecordValue = record.getFieldValue(parent_field_id);
    var newChildRecord = record.addNewRecordToField(link_to_form_field_id);
    newChildRecord.setFieldValue(child_field_id, parentRecordValue);

    Something like that should work.

    #51482
    Sarah Young
    Participant

    Is there a simple way, on creating a new child record, to set the value of a child field to a value in the parent record? I do not want these fields synced, I just want to set a default starting value on the child record.

    If not, it’s been nearly 10 years since I’ve written JavaScript (and I hated it then), so could use a pointer in the right direction for knowing Tapform specific syntax/object names.
    Thanks!

    Daniel Leu
    Participant

    We were stuck with an Act! database that forced us to use a VM to run on our Mac. Using a third party, we were able to export the entire database as CSV files and then import them into Tap Forms 5. With some custom layouts and scripts, we now have a CRM implementation that’s better suited for our needs than what we had when using Act!.

    A big plus, or even what enabled us doing this, is the Javascript API; and as I learned later, Brendan’s willingness to enhance it as needed.

    ‘hope this helps a bit!

    Cheers, Daniel

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

    Daniel Leu
    Participant

    The script runs in my demo form.

    The whatsapp field is of type Web Site, and phone number is of type Phone Number. You have to update the id for these two fields. You can find their values in the script editor on the left side.

    You skipped this step and this resulted in the error. You have to set phone_number_id and whatsapp_id according to your form.

    Regarding your new script, you can remove Nouveau_Script() as this is just the default template generated when creating a new script. Otherwise, the script seems to be okay, apart that the two field ids are not set.

    Cheers, Daniel

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

    Brendan
    Keymaster

    My technique will only complete the link when you click the globe button.

    I suspect your error arose from a copy and paste error. Daniel’s script looks proper to me.

    Also, in your script you can delete the boilerplate code Nouveau_Script() stuff.

Viewing 15 results - 211 through 225 (of 2,950 total)