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,306 through 1,320 (of 2,989 total)
  • Author
    Search Results
  • #44526
    Sam Moffatt
    Participant

    When you do a setFieldValue you need to also do a document.saveAllChanges() to ensure Tap Forms persists the change.

    Field scripts will trigger automatically when ever a field you refer to in the script changes, including when the record is created initially. If you want to run the script on demand, then you want to create a form script via the third tab instead of a field script. Form scripts only execute when you click the run button for it. If you’re after a situation where if you update a field that it refreshes the value of your target form. Depending on what you’re doing, you can also just use the script field to store the value and if you have a link to form field you can skip the search and traverse the link instead.

    I was looking at the document you sent but it seems out of date based on the field ID’s I see here. It does look like you’ve got a form (Categories) that also seems to be a pick list. You can get the pick lists though it doesn’t do the search for you so I’m wondering if that’s why you did it that way? You can also set up the pick list to update based on the form field directly which doesn’t seem to be how it’s configured.

    #44524
    robinsiebler
    Participant

    So, I guess the only way to do this is via a script. So, after much experimentation, I came up with a script that I think should work, but doesn’t.

    If I attach the script to the record, it seems that it fires immediately and fails, because the record is empty.

    If I add it to the scripts section and trigger it manually (which I very much don’t want to have to do), it gets the right value for the category, but fails to change the Category in the record.

    A) What am I doing wrong?
    B) How to I get a script to fire automatically after an item is selected?

    
    function getCategory() {
    
    	var selectedItem = record.getFieldValue('fld-097c3d751c854b1fb4b528238d48b2c4');
    	var records = 	document.getFormNamed('Products').getRecordsForSearchTerm(selectedItem);
    	return records[0].getFieldValue('fld-18643254818f4efbb85cdc66084ccec4');
    }
    
    function setCategory() {
    	var cat = getCategory();
    	console.log(cat);
    	record.setFieldValue('fld-104d11f1b0074b328dafd7688e87298c', cat);
    }
    
    setCategory();
    
    #44512
    Brendan
    Keymaster

    Hello Robin,

    To create a shopping list form:

    1. Create your new form by tapping the Add Form button.
    2. Add the fields you want to track:

    Acquired / Checkmark
    Item Name / Text
    Quantity / Number
    Category / Text
    Aisle / Number
    Description / Note
    Photo / Photo

    3. If the Acquired field is at the very top, you’ll get a Checkmark button on the records list view that you can tap on when you picked up that item.

    You would then add in all your items by creating new records and then entering in the Item Name and Quantity and other information that you have about the items.

    Then when you’re shopping, just display the list of items and tap on the checkmark button when you pick each one up.

    Before you go shopping the next time, you’d probably want to go through the list and uncheck the items that you want to buy again.

    If you group the records by the Checkmark field, you can have all of the unchecked ones at the top and all the checked ones at the bottom of the list of records.

    Hope that helps a bit.

    Thanks!

    Brendan

    #44510

    In reply to: Back up and passwords

    Brendan
    Keymaster

    Hi Hugh,

    You should move the one that’s in iCloud back into the Library folder. You should not open a Tap Forms document that’s sitting on a cloud storage service such as Dropbox or iCloud Drive.

    If you want backups to be in iCloud Drive for safe keeping, that’s fine. Set the Backup Folder on the Preferences window to a Tap Forms Backups folder you can make on iCloud Drive.

    But if you open and work on the document that’s sitting in iCloud Drive, you risk the embedded SQLite file becoming corrupted due to iCloud syncing things behind Tap Forms’ back.

    The reason you are seeing the file appear back in Library, but empty this time is that you probably also have iCloud Sync enabled for that document and Tap Forms is downloading the placeholder document for you from Apple’s CloudKit servers.

    Scripts has nothing to do with this issue.

    Thanks,

    Brendan

    #44506

    In reply to: Back up and passwords

    Brendan

    There are two identical copies of the file, one in Library/Containers/Tap Forms Mac 5/Data/Documents, the other in a sub-folder of iCloud/Documents.
    If I close Tapforms, it automatically backs up the file (into the correct Backup folder in Library – this does not seem a problem at all.)
    When I next load Tapforms it shows both versions in “Recent”. The one in Library opens without the password, the one on iCloud needs the password. (When I make changes, they appear identically in both files.)
    If I open the file directly from either Documents or Library in Finder, I get the same result.
    Later:
    I have now tried moving the file in Library to Bin then reopened Tapforms; the file immediately appeared in Library even before I tried to open it. This Library version is (now) empty, when I open the one from iCloud it requires the password. But both versions appear in Recent and again, password required for the iCloud one, not for the (new, empty) Library one.
    I wish to keep it in iCloud for the off-site back up, how can I prevent it appearing in Library?
    There is a setting in Preferences for Scripts which is set to Documents. I don’t use scripts though there is one that I was playing with in the file – could this be muddling things?
    Hugh

    #44485
    Sam Moffatt
    Participant

    A path forward might be using a script field and Javascript’s template strings as the template and set the Markdown field.

    You can use the script field to get all of the fields you’re interested in. Then you can use the template strings to compose the Markdown content and set it to a Markdown field. As the fields you reference in the script field are changed, the Markdown field will be updated automatically based on the template in the script field.

    Here’s a quick sample from a movie library (maybe the TF sample one?) which has a few extra fields in it. This shows pulling in a number of fields, handling a table field to gather records (actors) and doing some simple composition. It uses template strings to compose the individual lines with the actor in it and the final Markdown string. The last few lines set the field value of the Markdown field I created, tells Tap Forms to save all changes (very important) and returns the raw Markdown so that I can debug in the script editor.

    
    function Md_Generator() {
    	var movie_title = record.getFieldValue('fld-987c9aac738a4f0fa1d18395902b3fb1');
    	var barcode = record.getFieldValue('fld-7e3ead95de51427fa5a467b2476d58cd');
    	var summary = record.getFieldValue('fld-28cc8f7f082c43818f1169c96c96e5a9');
    
    	var photo_count = record.getFieldValue('fld-55340bfd611b411b87da481ae23e8db9');
    	var actors_total_cost = record.getFieldValue('fld-1837d1a6be83424a90e0e7ebdd6265e3');
    	var imdb_website = record.getFieldValue('fld-9bc90613e8db45fea77579f35eb53b9d');
    
    	var actorLines = [];
    	var actors = record.getFieldValue('fld-984cf79ccafb45a381b0f95b0aa28e78');
    	for(var actor of actors) {		
    		var first_name = actor.getFieldValue('fld-92b3b496a6cb4c20a32d36aa61e7a04f');
    		var last_name = actor.getFieldValue('fld-a907066570844290a27940d34de98b4f');
    		var fee = actor.getFieldValue('fld-b1ea1f22da5f421c93e1e20520e3ea22');
    		
    		actorLines.push(`- ${first_name} ${last_name} (Fee: $${fee})`);
    	}
    	
    	var actorString = "No actors listed."
    	if (actorLines.length > 0) {
    		actorString = actorLines.join("\n");
    	}
    
    	var markdown = `
    # ${movie_title}
    
    Barcode: ${barcode}  
    Photos: ${photo_count}  
    Actor Cost: ${actors_total_cost}
    
    ## Actors 
    ${actorString}
    
    ## Summary
    ${summary}
    
    ## Links
    - [IMDB Link](${imdb_website})
    `;
    
    	record.setFieldValue('fld-d0a67ce5cf1a4ab8b0a3e2357cc18d45', markdown);
    	document.saveAllChanges();
    	return markdown;
    }
    
    Md_Generator();
    
    #44469
    Brendan
    Keymaster

    Hi Juan,

    There’s no built-in function for doing substitutions like that outside of a static text object on the Mac version using a custom layout.

    With a static text object on a custom layout, you can do things like this:

    Dear [First Name],

    Your account is now overdue by $[Amount Due]

    Sincerely,

    The Management

    But it’s not using the Markdown editor. It’s just using the regular rich text editor.

    And you will see the substitution results only at print time.

    If you were to use a script running against the Markdown field, you’d just end up replacing the values. Although I suppose if you set the Default Value on your Markdown field to your template, whenever you added a new record, you’d get the untouched template value which you could then run a script on to do the substitutions.

    Thanks,

    Brendan

    Juan Borrás
    Participant

    Hi all!!

    I’m trying to figure out how to use the Markdown as a template for contracts.

    Is there anyway to search and substitute special “texts” in the markdown document via the script.

    For example, using %customer_name% and stuff like that?

    Thanks!

    #44448
    Brendan
    Keymaster

    Hi Kirk,

    The fields that are displayed on the inverse of a One to Many relationship are the same fields in the same order that you’ve specified on the parent form. So all you need to do is go to the parent form, rearrange the fields on the Fields tab and see what you get. You can also increase the number of fields that are displayed so that you get something more meaningful by clicking on the 1 to 5 buttons below the Single Column List View Fields option on the Form inspector panel.

    And yes, as TL Ford has mentioned, creating a calculation (or script) field will let you pick out individual fields from the parent form that could be displayed on the child form.

    Thanks,

    Brendan

    #44442
    Kirk Williams
    Participant

    Apologies if this is basic, but I seem to keep getting tripped up with some of these “minor” UI details!

    I would like to specify the field displayed on the parent form of a one-to-many relationship. Here’s my (hopefully) simple example:

    Form 1 contains a list of “computers”
    Form 2 contains a list of “users”
    Form 3 contains a list of “networks”

    I need to associate a “user” with a “computer”. To do this, I’ve added a “Link to Form” field in the “computers” form, set it as one-to-many, selected the “users” form, and checked “Show inverse relationship”. After doing this, I am able to select a user record and modify its displayed fields from within an individual computer record.

    Now that the records are linked, I can see a “Link from form” field in the “users” form, and the relationship I just created is present. The problem is that the field displayed on the users form is just a numeric ID (leftover from SQL dump). I have not found any way to specify which field(s) from the “computers” form (which I presume to be the parent in this example) is shown.

    Ideally, I’d like it to display something more identifiable, like a “name” or “description”, however I’d really like the ability to choose dynamically. For example, I would also like to create a second relationship in which a computer is linked to a network… for that link, I may want to display different data in the “link from form” field, such as an IP address, MAC address, etc.

    I hope this is making sense. Thanks in advance for any guidance!

    #44427

    In reply to: Just a little help.

    Sam Moffatt
    Participant

    I did a quick test with a website field and this sort of syntax worked:

    mailto:"Test User" <test@example.com>
    

    I couldn’t get the email field to do what I expected it to do but this opened up Apple Mail for me and had the details prefilled. It’s almost certainly non-standard.

    For your example:

    function SMS() {
    
    	var mobilephone =
    record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g,
    '');
    	var name = record.getFieldValue('fld-123456'); // replace this
    	 	
    	var SMS = `mailto:"${name}" <${mobilephone}@textmagic.com>?subject=Hello, World&body=Hello ${name}`;
    	//console.log(SMS);
    
    	const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d';
    	record.setFieldValue(email_id, SMS);
    	document.saveAllChanges();
    	
    	return SMS;
    
    }
    
    SMS();
    

    It’s a little more but seemed to work for me with Apple Mail. Javascript uses the backticks to denote “template strings” which means we can use variables a little more naturally than messing with plus signs. I also added an example of setting a subject and a body, no idea if that’s useful to your use case (if not, just remove them but perhaps worth a try). There are some limits on what you put in the field to ensure it makes it to Mail but give that a spin and see how you go.

    You’ll have to change the field type over from email to website but otherwise you should get a similar experience.

    #44425
    Andrew Drapper
    Participant

    A few weeks ago you all helped me come up with this great little script that lets me send an email through TextMagic and my customer receive it as a text message. It has been working FANTASTCLY… However, If I just add to it a little bit… I will know who I have texted when they reply.

    I need to edit the code so that rather than just an email address as

    “phone_number@textmagic.com”

    we go one step further and have

    “full_name field <phone_number@textmagic.com>”

    Existing code.

    function SMS() {
    
    	var mobilephone =
    record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g,
    '');
    	 	
    	var SMS = mobilephone + "@textmagic.com";
    	//console.log(SMS);
    
    	const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d';
    	record.setFieldValue(email_id, SMS);
    	document.saveAllChanges();
    	
    	return SMS;
    
    }
    
    SMS();

    Many thanks

    #44418
    Sam Moffatt
    Participant

    I have a simple intro to scripting video and a script field deep dive video that might help as well. Scripting is weaved into a bunch of the videos to solve various problems, perhaps overused at times but pretty powerful.

    If the gender is important, I’d make it a field and then you can do an IF comparison in either the calculation field or the script:

    IFEQUAL([Gender];"Male"; "Herrn"; "Fraun")
    

    You could make it a checkmark field though I think a radio pick list makes a little more sense.

    Javascript makes that a little clearer:

    var title = "";
    var gender_id = "fld-1234";
    switch(record.getFieldValue(gender_id)) {
      case "Male":
        title = "Herrn";
        break;
      case "Female":
        title = "Fraun";
        break;
      default:
        title = "";
        break;
    }

    You could also make the title a pick list of a set of valid titles and then something like this perhaps could work:

    var title = "";
    var title_id = "fld-1234";
    switch(record.getFieldValue(title_id)) {
      case "Herr":
        title = "Herrn";
        break;
      case "Frau":
        title = "Fraun";
        break;
      default:
        title = record.getFieldValue(title_id);
        break;
    }

    It’s a little longer than a replace statement but it’s perhaps a little clearer.

    #44415
    Brendan
    Keymaster

    Hi Kimberly,

    TL Ford, one of my Tap Forms customers has created a series of tutorials on Tap Forms Scripting 101 that may help you to better learn how to do scripting within Tap Forms. Some of those other JavaScript tutorials are more geared towards integrating JavaScript into web pages.

    http://cattail.nu/tap_forms/tap_forms_scripting_101/index.html

    As for the switch between Herr and Herrn, if you have some way to identify a male contact from a female contact, other than having that title, then you could use an if/then statement in JavaScript. But if you have a field in your form that already contains the values Herr or Herrn depending on the gender, then you could just insert that into your script (or Calculation field as in Sam’s solution).

    Thanks,

    Brendan

    #44408
    Kimberley Hoffman
    Participant

    Hi Sam,
    Thank you for your help. Your video also helped me with something I haven’t yet had time to fix: my acquisition, client and projects forms.

    Back to the address label:
    The German language is a little complicated. If the addressee is male, his honorific would be “Herr”. But if you write the address for a label, the word “Herr” is no longer the grammatical subject but appears in the grammatical accusative form “Herrn”.

    Unfortunately I am not versed in scripting. I just looked up scripting 101 on the web and am already overwhelmed. I think I should be looking for Javascript return values definitions.

    I’m guessing that I would have to insert part of the script like this?

    let myText = ‘Herr’;
    let newString = myText.replace (‘Herr’, ‘Herrn’);
    console.log(newString); //

    It is definitely worth learning some basics to get more out of the Tap Forms. For this book project I will use your solution and then for my fixing my project and client files, I’ll try to follow what you showed in your video, as I can always change that on my participant list I am working on now. Maybe you have a link to even more basic scripting? Thanks.
    Regards,
    Kimberley

Viewing 15 results - 1,306 through 1,320 (of 2,989 total)