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 - 256 through 270 (of 2,989 total)
  • Author
    Search Results
  • #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.

    Jo M
    Participant

    Wow !

    Well, first of all, thank you so so so much for your answers guys ! I appreciate so much and it helps me to improve myself as much as I can but it’s not that easy when you’re a beginner all alone

    In fact, I want to do this kind of things with many fields such as links for Whatsapp, Telegram, Instagram and so on in order to create a big adress book of my contacts.

    The script you created seemed to contain an error (or I don’t know but I had an error message) that I could solve thanks to chatGPT (I wasn’t able to do it alone) :

    The issue is in the following line:

    javascript
    const phone_number = var phone_number_id = ‘fld-XXX’;
    In this line, you declare a constant (const phone_number) and try to initialize it with another declaration (var phone_number_id). This is not valid in JavaScript because a declaration cannot be used as an initialization value.

    Fix
    You need to separate the declarations and initializations properly. Here’s a corrected version of the script:

    Changes Made
    Separated Declarations:

    Removed const phone_number = var phone_number_id = … and declared phone_number_id and whatsapp_id_id separately.
    Correct Identifier Usage:

    Used phone_number_id and whatsapp_id_id in the appropriate places.

    I tried another one by myself, can you tell me what you think (take a look at the type of the field because it’s not a number phone here) ? It seems to work perfectly :

    function Nouveau_Script() {
        // Replace with your own code
        var hello_world = "Bonjour tout le monde !"; 
        return hello_world;
    }
    
    Nouveau_Script();
    
    function Script() {
        // Define used fields
        const id_id = 'fld-XXX';
        const lien_id_id = 'fld-XXX';
    
        // Define Twitter API
        const lien = "https://twitter.com/i/user/";
    
        // Get the ID from the record (assuming this method exists)
        let id = record.getFieldValue(id_id);
    
        // Define call URL
        let url = lien + id;
    
        // Set URL
        record.setFieldValue(lien_id_id, url);
    
        // Save changes
        document.saveAllChanges();
    
        // Output result to console
        console.log(url);
    }
    
    Script();

    – Is there a way to add the ID directly to the link or have I to create a 3rd field in which there will be [Link] + [ID] ? Or at least I’ll hide the useless field with the default value.
    – If I use the method of Brendan : will it create a complete link in the tapforms app (I mean will it combine the two fields in the link field and show the complete link or will it combine only if I click on the globe button in order to access to the website) ?

    Sorry in advance for my English mistakes.

    Best regards,
    Jo M

    (sorry for the duplication but I edited my message and it doesn’t appear so I post it again)

    Daniel Leu
    Participant

    Hi Jo,

    You can use the concat function or just + in the calculation field to combine two fields. But this wouldn’t create a valid URL since the phone number uses the format +1 (123) 456-7890.

    Here’s a field script that takes the phone number as input and sets the URL field as the result. Then you can click on the url globe and the Whatsapp API is called using your default browser.

    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.

    function Script() {
    
    	// define used fields
    	const phone_number_id = 'fld-xxx';
    	const whatsapp_id = 'fld-xxx';
    
    	// define whatsapp API
    	const whatsappUrl = "https://api.whatsapp.com/send?phone=";
    	
    	// get phone number and format it to work with the API
    	let phone_number = record.getFieldValue(phone_number_id).replace(/[ ()-]/g,"").replace("+","00");
    	
    	// define call URL
    	let url = whatsappUrl + phone_number;
    	
    	// set URL
    	record.setFieldValue(whatsapp_id, url);
    	
    	// save changes
    	document.saveAllChanges();
    	
    	// output result to console
    	console.log(url);
    }
    
    Script();
    

    Cheers
    /daniel

    • This reply was modified 1 year ago by Daniel Leu.

    Cheers, Daniel

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

    Jo M
    Participant

    Hi the community !

    I am a new user of tapforms since a few months but I want to develop my skills in automation and so on.

    Is there a way to create a script that combines 2 records and that automatically fill a field ?

    I explain myself :

    Field 1 : number phone field entered manually
    Field 2 : link field : https://api.whatsapp.com/send?phone= > this field never changes it’s a default value
    Field 3 : I want to automatically combine field 2 + field 1

    I tried with chatGPT, it gave me something that seemed to work but it doesn’t.

    So, my question is : is it possible to do so and is it possible for one of you to help me with this kind of script ?

    Thank you so much for your answer and sorry for my english if I did mistakes I am french ahaha

    Best regards,
    Jo M

    #51407

    In reply to: Previous Record Script

    Daniel Leu
    Participant

    Hi Glen,

    Set the return type of your Today & Previous script to number! As text, it concatenates the fields instead of adding them.

    Here’s the yesterday’s hours script:

    function yesterdays_hours() {
    	
    	var records = form.getRecords();
        	var currentRecordIndex = records.indexOf(record);
    
        	if (currentRecordIndex > 0) {
            	var previousRecord = records[currentRecordIndex-1];
        	} else {
         		return 0;
        	}
    	
    	var today_hours_id = 'fld-7ecb8ad8fe3a4b6db80ea939a60accb2';
    	var yesterday = previousRecord.getFieldValue(today_hours_id);
    	
    	console.log("Yesterday: " + yesterday)
    
    	return yesterday;
    }
    
    yesterdays_hours();

    Cheers, Daniel

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

    #51405
    Glen Forister
    Participant

    I used this before with rain and it works in that Form. I copied the working script for rain and used it here.
    I changed the fld- numbers to be for this form.
    The calculations seem to be doing something unexpected.
    Please tell me what is wrong?

    If you get this to work, another question is how do I get the total sum from one record displayed in the next record?
    In each record I want to show
    Today’s hours
    Yesterday’s total hours
    Today Total hours (which is the sum of the above.

    I like to see these so I know the math is working and I can easily check.

    Attachments:
    You must be logged in to view attached files.
    #51404

    In reply to: Tables

    Brendan
    Keymaster

    There’s no function to get the “previous record” in order to get a total. The previous record can change depending on what your sort ordering is.

    But you can click the little Sigma ∑ button to show the calculation row so you can see the grand totals for the values in a Table field. What do you mean where can you put it so you can see it? It’s at the bottom of the Table field.

    Do you mean you want the total for that column to appear in the parent form somewhere in a separate field? If so, you can add a Calculation field or Script field to compute that value and display it in the parent record.

    The fields that are available to you are mostly the same as the fields that are available to you in a regular form. But only the more simple field types and not the complex ones like Link to Form, Table, File Attachment, etc.

Viewing 15 results - 256 through 270 (of 2,989 total)