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 - 946 through 960 (of 2,989 total)
  • Author
    Search Results
  • #46914
    Daniel Leu
    Participant

    Just a little update to my field script:

    function recordColorScript() {
    
    	const yes_no_id = 'fld-xxx';
    	const yes_no = record.getFieldValue(yes_no_id)
    	
    	if (yes_no == "Yes"){
    		record.setRecordColor('#00FF00') // green
    		console.log("set color for yes")
    	} else {
    		record.setRecordColor('#FF0000') // red
    		console.log("set color for no")
    	}
    	document.saveAllChanges()
    	
    	return yes_no
    }
    
    recordColorScript();

    Cheers, Daniel

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

    #46909
    Daniel Leu
    Participant

    The Javascript API is documented at https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api. Things like object.text.color or object.backgroundcolor are not supported. But there is record.setRecordColor('#cc9900');

    Maybe this works for you:

    function recordColorScript() {
    
    	const yes_no_id = 'fld-xxx'
    	const yes_no = record.getFieldValue(yes_no_id)
    	
    	if (yes_no){
    		record.setRecordColor('#00FF00') // green
    	} else {
    		record.setRecordColor('#FF0000') // red
    	}
    	document.saveAllChanges()
    }
    
    recordColorScript();

    Cheers, Daniel

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

    #46908

    In reply to: Help with a script 2

    Stig Widell
    Participant

    Thanks for info. It makes me understand now that there is no need for a script.
    I can manage everything without.

    #46907
    John McArthur
    Participant

    Thanks for that Brendan.

    I followed your instructions and the Pick list does show a small coloured bar to the left of the selection but when you click on the selection the coloured bar doesn’t appear in the field.
    It would be much easier if the record was blatantly obvious showing the person was deceased.
    ie the field background colour turns Black.

    I was playing around with script trying to achieve the colour changes but most web ‘help’ refers to HTML/CSS options. There is little help with regards to syntax for pure javascript, or there are conflicting ‘color’ coding syntax versions.

    See my feeble attempt at scripting below. :)
    Do I just need to correct the syntax for ‘colour’ related code for TF? …

    function Cl1_expired() {

    // Change text box colour when checkbox is ticked

    var cl1_deceased = record.getFieldValue(‘fld-8e6c8ac1b14446088d6f4443f103efd7’);
    var cl1_full_name = record.getFieldValue(‘fld-f86ccf72fcf848669d17db555ca697f3’);

    if (cl1_deceased = true) {
    // true condition;
    cl1_full_name.backgroundcolor = “black”;
    cl1_full_name.text.colour = “yellow”;

    } else {
    // false condition – do nothing
    }

    }

    Cl1_expired();

    #46904
    Brendan
    Keymaster

    Hi John,

    I would suggest instead of a Checkbox, use a Pick List. In a Pick List you can assign colours to the values. Then on the Form properties, set the “Record Colour Field” option to be the field you’ve assigned that Pick List to. Then when you select a value from that Pick List in your record, Tap Forms will display a coloured bar next to the record. So then at a distance you can easily see which records represent deceased individuals.

    No scripting required.

    Thanks,

    Brendan

    #46902
    John McArthur
    Participant

    Hi,

    I’m looking for a way to change a name field when a person is deceased.
    I currently have a ‘Full Name’ field (concatenated from other name fields, with a grey background) and a ‘Deceased’ check box.
    When the check box is ticked I would like the ‘Full Name’ field to have a black background with yellow text.
    Sounds simple enough but I’m a newbie to scripts so not sure how to trigger the change when the check box is ticked.
    Any help would be gratefully appreciated.
    Many thanks

    #46894
    Stig Widell
    Participant

    The Swedish farmer has received successful help with earlier scripts.
    But there is a need for one further script and the knowledge in JavaScript is still nonexistent.
    So help with a form script is most welcome!!
    A document template of “Djur” is enclosed.

    This is the background:
    In the form “Kalvningar” are calves from the season listed. They will be split into three groups:
    – female calves kept for breeding
    – female calves for sale (the rest)
    – male calves for sale

    The script should perform the following:
    Go through all the calf records and check:
    1. if a female calf and the field “Utgångsorsak” IS NOT empty (breeding info already entered): enter a transaction date in the field “Utgångsdatum” for each record and make a copy of these records with information in fields “Utgångsdatum” and “Utångsorsak” deleted ie. empty and transfer these copies over to the form “Rekryteringsdjur”.
    2. if a female calf and the field “Utgångsorsak” IS empty:
    – enter a sales date (to be typed in) in field “Utgångsdatum” and the information “Försäljning” in field “Utgångsorsak”.
    3. if a male calf and the field “Utgångsorsak” IS empty:
    – enter another sales date (date of sale for males and females not the same) in field “Utgångsdatum” and the information “Försäljning” in field “Utgångsorsak”.

    If both the fields Utgångsdatum” and “Utgångsorsak” IS NOT empty: go to next record.

    Finally should the group information in the field “Grupp” in the form “Rekryteringsdjur” for all records in that form be deleted so that the field is empty.

    Now the data base is prepared for a new calving season.

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

    In reply to: Help with a script

    Stig Widell
    Participant

    Sam, I regard the Kalva-script as a big success.
    Thank you very much for your help.
    As I indicated in this thread on 12 feb there is a need for one further final script in the document Djur.
    If you have time and still got inspiration I would ask you to help me with that one as well.
    This thread is too long so I intend to start a new one for that script.

    Bruce Meikle
    Participant

    Hi Sam,

    Excellent! It does make sense. That achieves exactly what I want to do – in a simpler database. I am still having issues in the more complex example that prompted the question (an additional blank account record is created now), but the simpler model works. I need to spend some debug time on my main database, but now that I now what is involved, hopefully I can solve it.

    The saveAllChanges after each record change doesn’t appear to make much difference but I get what it is trying to achieve. It sounds like a good practice to use.

    BTW – I have learnt a lot about the JavaScript/TapForms model from your YouTube videos. Very helpful. And thanks for your very quick response to this question!

    • This reply was modified 3 years, 10 months ago by Bruce Meikle.
    Bruce Meikle
    Participant

    I’, new to Javascript and relatively new to TapForms. I need to replicate the “Select and link existing records” function in a script. In certain circumstances I am creating a new “transaction” (new record) inside a script (using AddNewRecordToField) and once created I need to set the “Link From Field” to an existing “account” record in the script so that the user doesn’t have to take the extra records to go to the subform and select (probably the wrong) “account”, or even worse, not select one at all.

    In summary:
    1. A new transaction item is created in a script using AddNewRecordToField();
    2. I need to update the “Link from field” to select an existing account record inside the script;

    Is this possible, and if so how would I do it?

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

    In reply to: Help with a script

    Sam Moffatt
    Participant

    One has the latest changes in it, one I think will be out of date. Just nuke the script that doesn’t have the changes I noted above.

    #46875

    In reply to: Help with a script

    Stig Widell
    Participant

    Japp, I did as Brendan wrote and it worked. Everything looks just fine. Marvelous job you have done Sam. I am so grateful.
    The two “Kalva” scripts should both be there? I ticked the first one.
    Enclosed please find two print screens with questions.

    Attachments:
    You must be logged in to view attached files.
    #46874
    Brendan
    Keymaster

    Hi Alan,

    There’s no direct way to sort on fields that are in related forms.

    But you could pull out the data from your Join field to display it in the parent form. You’d need a script to do that though. And because a Join field is a many to many relationship, you could possibly have multiple values in that field. So you would need to build up a string that concatenates all of the values and then sort by that on the parent form.

    Or if you’re only interested in the first value of the relationship, you could just pick out the first value from that field.

    Here’s information on scripting:

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

    On the Script Edit screen there are snippets. One of them is called Child Records Loop. If you select a field from your Link to Form field, then double-click on the Child Records Loop snippet, Tap Forms will write the code for you that you would need to loop through all the records of the Link to Form field. You would then just need to augment that with code to concatenate the values from the field into a single string. Then you can sort your parent form by that Script Field.

    Hope that makes sense.

    Thanks,

    Brendan

    #46824
    Brendan
    Keymaster

    Hi Lorenz,

    You would probably want to write a Form Script to add the reminders. There’s a function for adding to reminders available in the Script engine.

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

    You can create a Saved Search that just searches on the months. You just need to be able to extract the month name from the birthdate field.

    Add a Calculation field with the following formula:

    DATE(Birth Date; "MMM")

    Insert the field into the formula properly. Don’t just type the name. On macOS you would double-click on the field name on the formula edit screen. On iOS, surround the field name with square brackets (e.g. DATE([Birth Date]; "MMM") ).

    Now you can create Saved Searches that just looks for the month name and it wouldn’t matter what the year and day was.

    • This reply was modified 3 years, 11 months ago by Brendan.
    Brendan
    Keymaster

    Sorry for the confusion with the sample script. The update function was there only to show that you can update an event, not that you should add and then update all the time.

    I’ve updated the documentation to show that the updating is optional and should probably be done sometime later and that you’d have to store the identifier in another field.

    Sorry this caused you this trouble. But thanks for pointing out this issue.

Viewing 15 results - 946 through 960 (of 2,989 total)