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 - 1,846 through 1,860 (of 3,011 total)
  • Author
    Search Results
  • #41306
    pierrot_rennes
    Participant

    Hi Sam,

    I put only one keyword per article to keep it simple
    If I really need a second keyword for the same item, I create a second record
    Apparently, your script works according to my need.
    I will test by adding some articles.
    If it’s ok, I will start from your model to modify your form and adapt it to my needs
    A big thank you for your responsiveness, I will tell you when it’s good

    #41302

    In reply to: A Few Questions

    Sam Moffatt
    Participant

    Hi Christin,

    Responding as a regular user, some of these will require Brendan’s input.

    1. I suggest looking at CouchDB or Cloudant as the sync system, I’ve found CouchDB to be reliable and if you’ve only got a small amount of data the IBM Cloudant free tier I think gives you 1GB of space to use (CouchDB is an open source server and Cloudant is IBM’s hosted version of it).

    2. I’d probably leave all of those fields in a single form with a “type” field and then use custom layouts to control which quote you saw. It won’t work so well on the table view but a workaround would be to use either a calculation field or a script field to compose the text relevant to the record type, perhaps like a bibliography line generator. You click add, in the ‘quotations’ form select the right layout for th type, put in the data and then you can go back to the parent form.

    3. Companies are people too, at least in the US anyway. I’d actually take inspiration from Apple’s approach where if a contact card is a company is a tick box for the contact card and everything else more or less remains the same. You can still filter and search on if something is a company or not and if you bump it up your field list after name, you can have it render in the list view as well (I’d also tick “show field name” on the checkbox as well). I don’t think you can hide the UI if there is nothing there.

    4. Many to Many implies both sides could have multiple entries though, that’s why it’s displaying the table because there is the possibility that multiple records will be available or another one could be added even if there is currently only a single record.

    5. I’m not sure I fully understand so my apologies if I’m off base but what might work for you is something not dissimilar to what I just threw together for Pierrot for his keywords mapping for magazines. Some amount of scripting could help automate building the linking structure you’re interested in achieving though I must admit I’m not sure I fully understand it. There are a couple of ways of structuring the forms to use calculation or script fields to create surrogate field values (e.g. take the name of the current level such as Habits and then prepend a field with the name of it’s parents) which if set to be the first field shows up in the flat list but can maintain the parent association via a 1:M link. Then I’d probably use a normal Link to Form M:M field to map the children of each of the category records to it’s categories that is maintained by a script. You could brute force like the above script or a field script might also work to detect links being manipulated and to automatically propagate adding/removing the links internally.

    Hopefully that makes sense, I’m sure others on the forums might have different takes and Brendan often chimes in with features that are built in that might handle some of it. I think with some scripting support you can get a little bit further.

    #41299
    Sam Moffatt
    Participant

    If you only had one keyword, then I think a JOIN link to field type would work for you because you could have a single “keyword” record and then it’d automatically JOIN on other records. If you made “articles” it’s own form and used “Link to Form” fields to join it all together then that would work. You’ve gone with a table approach which can’t be used to handle the JOIN.

    If you wanted to keep the table, what could work is to leverage a script to maintain the links. I did a really quick one here;

    function Build_Keyword_Map() {
    	// This is the other form that has our keywords in it.
    	let keywordForm = document.getFormNamed('Keywords');
    	
    	// This is the field ID in the "keywords" form for the link to field to Magazines.
    	let magazines_id = 'fld-b4724a28d4094b3faa9910f18374588f';
    
    	// This is the field ID in the "keywords" form for the keyword field.
    	let keywords_keyword_id = 'fld-ebaf7ffa3d484834bdcc34d3ffb9c5f2';
    	
    	// This is the field ID in the "magazine" form of the table.
    	let articles_id = 'fld-dca513dfa3894e8aaa3792a9eb09b106';
    	
    	// This is the field ID in the "magazine" form for the keyword field in the articles table.
    	let keyword_id = 'fld-055da0f29f764ea399e6f317427ff8ed';
    
    	// This is to store a map of keyword to keyword record.
    	let kwRecords = {};
    
    	// Build the map of keyword to keyword record (cache if you will).
    	for (let keywordRecord of keywordForm.getRecords())
    	{
    		kwRecords[keywordRecord.getFieldValue(keywords_keyword_id)] = keywordRecord;
    	}
    
    	// Iterate over every record in this form...
    	for (let sourceRecord of form.getRecords())
    	{
    		// And iterate over each row in the articles table...
    		for (let article of sourceRecord.getFieldValue(articles_id))
    		{
    			// Get the value of the keyword field...
    			let keyword = article.getFieldValue(keyword_id);
    			
    			// Skip it if it is empty...
    			if (!keyword)
    			{
    				continue;
    			}
    
    			// Check if a keyword record exists for it...
    			if (!kwRecords[keyword])
    			{
    				// Create keyword record if it doesn't exist...
    				console.log('Creating keyword record');
    				kwRecords[keyword] = keywordForm.addNewRecord();
    				kwRecords[keyword].setFieldValue(keywords_keyword_id, keyword);
    			}
    			
    			// Link the keyword record to this record.
    			kwRecords[keyword].addRecordToField(sourceRecord, magazines_id);
    			
    			// Save the changes to make sure the link persists properly...
    			form.saveAllChanges();
    			
    			// Log the keyword we processed, we're done!
    			console.log(keyword);
    		}
    	}
    }
    
    Build_Keyword_Map();

    There are comments throughout which should explain what it does and I’ve attached a sample archive with the script in it inside the “Magazine” form. You can play with it to get it to add links. What it doesn’t do right now is handle if you delete or remove a keyword. You’d also have to do a split or similar to do a comma separated list of keywords as well but this is a quick example of how you can use scripting to build that link.

    If you change from a table to a child form then you could link a single keyword easily. If you wanted to do multiple keywords (e.g. Big Sur, Photos) then you’d be back needing a script again.

    Hopefully this helps :)

    Attachments:
    You must be logged in to view attached files.
    #41279
    Roy Helsing
    Participant

    I am new to TAP, and made a simple relational database for a lost of music I can play, attached to the genres that relate to that music. I want to be able to print a report for my customers that lists each genre and under it, all song titles that are related tot hat genre. It appears the thinly way to do that iw with a script – which I read about at length yesterday only to decide Java Script is not in my wheel house. Does anyone have a simple script they use to list related items under a field that could share? I think i am able to figure out how to replace the fields in someone script with my one. I am looking for a report that reads like this:

    GENRE 1
    Song 1
    Song 15
    Song 432
    Genre 2
    Song 15
    Sonf 321
    Genre 3
    Song 1
    Song 12

    #41263
    Sam Moffatt
    Participant

    You can use any of the scripts I wrote with pick lists. You just need to define the two pick lists in the Tap Forms preferences for your document and assign each of the text fields to the correct pick list. Make sure you use a single value select list type (e.g. single value popover, combobox, popup button or radio) because the multivalue varieties would mess up the mapping.

    #41257
    Brendan
    Keymaster

    Oops. Actually you’re right. Because the script doesn’t get executed until you select from the first pick list. Darn.

    #41249
    Brendan
    Keymaster

    I know it’s not the same as what you’re doing, but I did once write a script that switched pick lists depending on the value selected from another Pick List. This script switches between a Canadian Provinces and US Sates Pick List depending on the value of the country selected.

    function Province_Pick_List_Switcher() {
    
    	var country_id = 'fld-de7985c881804154b037c68dc4c24414';
    	var country = record.getFieldValue(country_id);
    	var canadian_provinces_pick_list = document.getPickListNamed('Canadian Provinces');
    	var us_states_pick_list = document.getPickListNamed('US States');
    	var province_id = 'fld-b1458c16690744129ff145f7b9607c99';
    	var province = form.getFieldWithId(province_id);
    	
    	if (country == 'Canada') {
    		province.pickList = canadian_provinces_pick_list;
    		
    	} else if (country == 'United States') {
    		province.pickList = us_states_pick_list;
    		
    	} else {
    		province.pickList = null;
    	}
    	
    }
    
    Province_Pick_List_Switcher();

    It worked well, but only with the Single and Multi-Valued Pick Lists. Because those fetch their Pick List values when you display the popover as opposed to the Checkbox, Radio Button, Combo Box, etc., which pre-load all the values to display.

    #41244
    Sam Moffatt
    Participant

    I re-read this and thought I might be overthinking things, if you want a simple 1:1 mapping something like this might work for you. Create a script field and then use a switch statement to pick the right value.

    Here’s an example of autocompleting a country based on a “state” field. I use a switch because I think it’s pretty readable though you could construct an array as well:

    function Autocomplete_Country() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    	var country = '';
    	
    	switch (issuing_state)
    	{
    		case 'Washington':
    		case 'Oregon':
    		case 'Texas':
    		case 'Nevada':
    		case 'Arizona':
    		case 'Florida':
    		case 'New York':
    		case 'California':
    			country = 'United States of America';
    			break;
    		case 'New South Wales':
    		case 'Victoria':
    		case 'South Australia':
    		case 'Tasmania':
    		case 'Western Australia':
    		case 'Northern Territory':
    		case 'Australian Capital Territory':
    		case 'Queensland':
    			country = 'Australia';
    			break;
    		case 'British Columbia':
    		case 'Alberta':
    			country = 'Canada';
    			break;
    	}
    	
    	return country;
    }
    
    Autocomplete_Country();

    Basically in the case lines you put each of the values you want to match and then set a variable (in my case country) to be the value you want. You can then return it and it’ll display.

    Here’s the same thing implemented as a map/dictionary:

    function Autocomplete_Country_Map() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    
    	var state_map = {
    		'Washington':  'United States of America',
    		'Oregon': 'United States of America',
    		'Texas': 'United States of America',
    		'Nevada': 'United States of America',
    		'Arizona': 'United States of America',
    		'Florida': 'United States of America',
    		'New York': 'United States of America',
    		'California': 'United States of America',
    		'New South Wales': 'Australia',
    		'Victoria': 'Australia',
    		'South Australia': 'Australia',
    		'Tasmania': 'Australia',
    		'Western Australia': 'Australia',
    		'Northern Territory': 'Australia',
    		'Australian Capital Territory': 'Australia',
    		'Queensland': 'Australia',
    		'British Columbia': 'Canada',
    		'Alberta': 'Canada'
    	}
    		
    	return state_map[issuing_state];
    }
    
    Autocomplete_Country_Map();
    

    It’s a little more concise though you’re writing down the country name each time so possible to get it wrong.

    If you’re not after a direct 1:1 mapping of values between two fields, then we can continue down the earlier pathway. If you’re only after 1:1 this would work for you.

    One last piece is if you want to make the field editable but still autocompleted, this script will handle that for you. In this case there are three fields: state, country and the script field. State and country are text fields whilst the script field is what we use to retain some state and set values. The script below handles this and includes a reference to itself to allow manual overrides to be preserved when autocomplete would overwrite:

    function Autocomplete_Country() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    	
    
    	var issuing_country_id = 'fld-108b77c0b088457d90671dd71edf3247';
    	var issuing_country = record.getFieldValue(issuing_country_id);
    
    	var autocomplete_country_id = 'fld-cf8a4c138a3a437991182f17000580d6';
    	var previous_country = record.getFieldValue(autocomplete_country_id);
    	
    	if (issuing_country && issuing_country != previous_country)
    	{
    		return previous_country;
    	}
    
    	var country = '';
    	
    	switch (issuing_state)
    	{
    		case 'Washington':
    		case 'Oregon':
    		case 'California':
    			country = 'United States of America';
    			break;
    		case 'New South Wales':
    		case 'Victoria':
    		case 'Queensland':
    			country = 'Australia';
    			break;
    		case 'British Columbia':
    		case 'Alberta':
    			country = 'Canada';
    			break;
    	}
    	
    	record.setFieldValue(issuing_country_id, country);
    	form.saveAllChanges();
    	return country;
    }
    
    Autocomplete_Country();
    #41243
    Sam Moffatt
    Participant

    The complexity comes in that you need to encode the knowledge so that the computer can present it. Then once you’ve encoded that knowledge you need to access it to present it back to the user. Unfortunately Tap Forms doesn’t directly have an implementation that could hide that complexity from you so that means we’re implementing the complexity to make it look simple.

    Let’s tackle the data modelling problem first for encoding which brands and which countries. The scripts I presented have a few different options, which is the most comfortable for you:

    1. form based: create a new form with two fields: one with the brand name and one with a comma separated list of countries (you could create a country pick list using the multi-value popover or checkbox options to make data entry easier)
    2. pick list based: create one pick list with a list of all of the brands in it and then for each brand create another pick list that defines the countries
    3. fully script based: encode everything into a single script file (probably a bad idea if you have a lot of data)

    I think creating a new form to store it is probably the best path forward all told. Let me know which one of those approaches of storing the mapping data of “brand” to “country” makes sense for you and we can move forward with getting this sorted.

    #41235
    Daniel Leu
    Participant

    Yes, this can be done. Unfortunately, everytime you update your checkbox field, you have to click on Recalculate Formulas to get the update.

    Here is my field script:

    var hide_field_id = 'fld-xxx';
    var target_field_id = 'fld-xxx';
    
    var field = form.getFieldWithId(target_field_id);
    var status = '';
    
    if (record.getFieldValue(hide_field_id)){
    	field.hideField = true;
    	status = 'hiding field';
    } else {
    	field.hideField = false;
    	status = 'showing field';
    }
    
    document.saveAllChanges();
    
    status;

    Cheers, Daniel

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

    #41234
    Jean-Pierre Hermans
    Participant

    Is it possible to hide different fields with a script? And if yes, can someone give an example because this is complete new for me.
    I have a checkbox and when it’s checked then some fields in that record needs to be hided.
    Thank you.

    #41233
    pierrot_rennes
    Participant

    Hi Sam,
    Thank you for your answer
    I went to see your code.
    I’m looking for something simple, so I’m going to refine my search.
    I have two selection lists: Brands and Countries.
    For example, when I select the Ravensburger brand in field 1, field 2 displays the country France
    Is it possible to define a script where each correspondence for brands and countries would be defined
    Thank you

    #41229
    Sam Moffatt
    Participant

    I’m not sure it’s possible to do that in Tap Forms with the default UI however I think you could easily create a form script with two prompters that did that for you. The input from the first prompter could be used to setup the second prompter which then sets the appropriate fields.

    A while back I did a post with a couple of different options on how you can make it work.

    #41220

    In reply to: Problem with If script

    Daniel Leu
    Participant

    Hi Victor,

    I noticed a few things:

    1. One of the pick list entries stated by a whitespace. You should remove that
    2. In your script, all branches need to be else if
    3. The address field selector should not be a checkmark, but a unique selector such as Single Value Popover

    With these changes, the script works for me.

    Here is the code I’m using:

    var address_field_id = 'fld-1f639ae503fe419b8473b02ea17d4ac4';
    var address_field = record.getFieldValue(address_field_id);
    
    let result = '';
    
    if (address_field=="newly identified - work address") {
    	result = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b');
    } else if (address_field=="already identified - work address") {
    	result = record.getFieldValue('fld-11915a3f275a4938949714a664dc40bf');
    } else if (address_field=="newly identified - personal address") {
    	result = record.getFieldValue('fld-0e624f31b7af41b18fcb0262a7ec2a0d');
    }
    
    result;

    Please note that sometimes you need to press Recalculate formulas to get the record’s fields updated.

    Cheers, Daniel

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

    #41218
    pierrot_rennes
    Participant

    Hi,
    I would like to be able to fill in a second field automatically based on the entry in another field.
    Is it possible in Tap Forms?
    Should we go through a script?
    For example, in field A, I enter a brand
    Field B automatically inquires with the corresponding country
    Thank you for your help

Viewing 15 results - 1,846 through 1,860 (of 3,011 total)