My first script … no effect

Tagged: 

Viewing 4 reply threads
  • Author
    Posts
  • October 24, 2020 at 12:13 AM #42385

    Christian Rommens
    Participant

    I am using the trial version of Tap Form. I wrote this first simple script but it doesn’t work. Could you tell me the error please :

    function Phonedemarcheur() {
    record.getFieldValue(Dem);
    if (document.form.Dem.value = “Yvon Lainé”){
    document.form.phoneDem.value = “06 xx xx xx xx” ;
    }
    }

    October 24, 2020 at 12:11 PM #42391

    Sam Moffatt
    Participant

    So record.getFieldValue() accepts a Tap Forms field ID and will return a variable with contents of that field for the currently selected record. In your example, Dem isn’t declared so you need to define it.

    On the left panel of the script editor should be a list of fields, click on your “Dem” field (I’m making a guess here) and then the little “ID” button should insert something like:

    var dem_id = 'fld-1234';
    

    I see you want to reference a phoneDem field as well, insert an entry for it, I’m going to assume it looks something like this:

    var phoneDem_id  = 'fld-4321';
    

    Now you’ve got the variable set up, you can then use this to get the value of the field:

    var dem = record.getFieldValue(dem_id);
    

    This gets the value of the field and puts it into the variable dem which you can then check to see if it matches your value:

    if (dem == "Yvon Lainé")
    {

    It looks like you’re trying to set a value back, so to do that you need to use record.setFieldValue. The first parameter is a field ID and the second is the value you want to set. You also need to tell Tap Forms to save your changes as well with document.saveAllChanges():

        record.setFieldValue(phoneDem_id, "06 xx xx xx xx";
        document.saveAllChanges();
    }


    @cattailnu
    on the forum has a Tap Forms JavaScript Scripting 101 that might help you get started as well.

    October 25, 2020 at 3:45 AM #42399

    Christian Rommens
    Participant

    Merci beaucoup Sam,
    malheureusement, cela ne fonctionne pas. J’ai vérifié la syntax auprès de @cattailnu. J’ai tout réécrit. j’ai utilisé la console ; parfois la valeur est retournée, parfois pas… Auriez-vous la gentillesse de m’aider à nouveau

    function Phonedemarcheur() {

    var dem_id = ‘fld-29c0876542164738814d28440b9c5e5e’;
    var phonedem_id = ‘fld-33891151ae8b488e9d359fed52f06aab’;

    var dem = record.getFieldValue(dem_id);
    // console.log(dem);
    // return dem ;
    if (dem == “Yvon Lainé”)
    {
    record.setFieldValue(phonedem_id, “06 00 00 00 00”);
    document.saveAllChanges();
    }

    }

    Attachments:
    You must be logged in to view attached files.
    October 25, 2020 at 6:13 PM #42406

    T.L. Ford
    Participant

    Christian, you are very close to the correct answer:

    function Phonedemarcheur() {
    
    	var dem_id = 'fld-29c0876542164738814d28440b9c5e5e';
    	var phonedem_id = 'fld-33891151ae8b488e9d359fed52f06aab';
    	
    	var dem = record.getFieldValue(dem_id);
    
    	console.log(dem);
    
    	//	This exits the function before your if() statement. I commented it out.
    	//	return dem ;
    	
    	if (dem == "Yvon Lainé")
    	{
    		record.setFieldValue(phonedem_id, "06 00 00 00 00");
    		document.saveAllChanges();
    	}
    
    }
    
    // You have to call the function to run it. I added it.
    Phonedemarcheur();
    October 26, 2020 at 11:02 PM #42427

    Christian Rommens
    Participant

    Many thanks for your help. Everything is working now. You have really helped me understand the use and application. Thank you again and have a good day

Viewing 4 reply threads

You must be logged in to reply to this topic.