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,276 through 1,290 (of 2,952 total)
  • Author
    Search Results
  • 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

    Sam Moffatt
    Participant

    The error is probably because let (or var) flags a declaration of a variable and you’re getting an error that you’re redefining a variable in the same scope or something like that.

    The first way of solving this is the second time you do the addNewRecord, you just drop the let prefix. If that’s your error then we should be good with this. Personally I’d avoid this because you’re re-using a variable pointing to a record which means that you lose access to the pointer or reference to that record. If that isn’t important to you then this is probably the easiest solution.

    The second is that newRecord is just a name that has meaning to us as humans. You could use a different name like let apostilleRecord = form.addNewRecord() and then later let legalisationRecord = form.addNewRecord(). This keeps them distinct and makes it easy to realise if you’ve made a mistake that you’re assigning something to the wrong variable (why am I setting the apsotilleRecord to be “legalisation services”?). If I’m going on to use these records, perhaps to link to another record (e.g. record.addRecordToField), then this is likely the approach I’d take (though in that case I’d use let newRecord = record.addNewRecordToField(linkToFormFieldId) because it’ll automatically create the link for me).

    The third approach would be to put this in a loop if we don’t need the reference to the field. This has the downside of the first situation where you lose the reference to the record but it also has a little more flexibility if you don’t need that reference. The advantage of this would be that you can add to the array the records you want to create and create them as necessary. A refactor might look like this:

    var date_id = 'fld-55a1678dc7b847f6be303140ad4779a3';
    var type_of_disbursement_id = 'fld-1214396547f84c9b8fcccac7917e0147';
    var unit_price_id = 'fld-8af21853bb8949bbbac92a1919fb5597';
    var number_id = 'fld-0616ad94503b4bd1b87bd4a1b0ce9d44';
    
    let entries = [{
            [date_id]: new Date(),
            [type_of_disbursement_id]: "apostille",
            [unit_price_id]: "30",
            [number_id]: "1"
        },
        {
            [date_id]: new Date(),
            [type_of_disbursement_id]: "legalisation service",
            [unit_price_id]: "24",
            [number_id]: "1"
        }
    ];
    
    for (let entry of entries) {
        let newRecord = form.addNewRecord();
        newRecord.setFieldValues(entry);
    }
    
    document.saveAllChanges();
    

    We set the field ID’s at the top, same as your script but we next create an array of entries. We’re hard coding them here which makes the loop a little pointless but it shows how we add stuff to a loop to create items. The square brackets (e.g. []) when creating a variable tells Javascript this is an array of elements. The {} syntax when creating a variable tells Javascript that this is an object, we’re going to use that a little later to set the record values. The inner part should look slightly familiar as what you were doing before via setFieldValue. In our usage objects can be thought of key/value pairs of entries. In this case the “key” is the field ID and we’re using the square bracket syntax here (e.g. [date_id]) to tell Javascript to use the value of date_id which is fld-55a1678dc7b847f6be303140ad4779a3. This makes things a little neater by removing an intermediate variable because we’re directly putting in the mapping. This example creates two objects (the comma in the middle after the } tells Javascript that another object should be expected), one for the “apostille” and one for the “legalisation service”.

    The next bit of code is a for loop that runs the same code multiple times for each values in the array. The first time through the loop the value of the variable entry is the “apostille” object and then the second time through it’s the value of the “legalisation service” object. Inside the loop (the curly braces in this context is creating a block, confusing right?) we’re running the same code which is creating a new record (form.addNewRecord) and then I use setFieldValues with the object we created to set all of the field values in a single step.

    The last line remains the same, we only need to do it once to tell Tap Forms to persist everything.

    Hopefully that helps you out with some ideas and solutions for moving forward.

    #44406
    Sam Moffatt
    Participant

    The calculation documentation has an example of how you can omit certain items if they’re not set. Starting with that example there as a basis with some modifications (square brackets to denote field placeholders):

    IFNOTEMPTY([Anrede]; CONCAT([Anrede]; " "); "") + [VORNAME] + " " + [Name] + "\r" +
    [STRASSE_HAUSNUMMER] + "\r" +
    [PLZ] + " " + [STADT] + 
    IFEQUAL([LAND]; "Deutschland"; ""; CONCAT("\r"; [LAND]))
    

    Something like this should work, the IFNOTEMPTY is checking if the Anrede field is not empty and if so it adds it plus concats a space on the end of it otherwise it puts in an empty string so there isn’t the whitespace. The IFEQUAL at the end should test for if the country name matches and if it does match then we return an empty string otherwise we put in the new line and the country name. I use CONCAT but the + syntax should work as well.

    This is the edge of what I’d put in a calculation field because they’re hard to debug once they start to get a little more complicated. Script fields are a little better at giving you at least an error when you mess stuff up. In terms of being flexible in the address generation, I’ve got a video on using a script field to generate addresses that focused mostly on using a linked form field but the same approach would work for formatting an address.

    Victor Warner
    Participant

    I would like to add more than 1 record to a Form at a time.

    For one record I have the following form script:

    var date_id = 'fld-55a1678dc7b847f6be303140ad4779a3';
    var type_of_disbursement_id = 'fld-1214396547f84c9b8fcccac7917e0147';
    var unit_price_id = 'fld-8af21853bb8949bbbac92a1919fb5597';
    var number_id = 'fld-0616ad94503b4bd1b87bd4a1b0ce9d44';
    
    var date = new Date();
    var typedoc = "apostille";
    var unitprice = "30";
    var number = "1";
    
    let newRecord = form.addNewRecord();
    
    newRecord.setFieldValue(date_id,date);
    newRecord.setFieldValue(type_of_disbursement_id,typedoc);
    newRecord.setFieldValue(unit_price_id,unitprice);
    newRecord.setFieldValue(number_id,number);
    
    document.saveAllChanges(); 

    But then if I also then wished another record using the same Form script to add:

    var date = new Date();
    var typedoc = "legalisation service";
    var unitprice = "24";
    var number = "1";
    
    newRecord.setFieldValue(date_id,date);
    newRecord.setFieldValue(type_of_disbursement_id,typedoc);
    newRecord.setFieldValue(unit_price_id,unitprice);
    newRecord.setFieldValue(number_id,number);
    
    document.saveAllChanges();

    What command do I need to use to create another record (as using

    let newRecord = form.addNewRecord();

    again results in an error)?

    #44399
    Brendan
    Keymaster

    The Prompter doesn’t have direct support for date input, so you would need to parse it yourself.

    Here’s a link to various solutions for that:

    https://stackoverflow.com/questions/5619202/converting-a-string-to-a-date-in-javascript

    #44395
    Sam Moffatt
    Participant

    Creating a new record is done by form.addNewRecord(). It’ll return to you a new record object that you can use.

    The other item is that prompter runs async which means that after the show() line, the script keeps running. Conceptually, think of that as the last line of the script and when it’s finished, it will call the function you gave it, output in this case.

    Some personal preference, I try to keep the variables that are being predefined at the top. It sometimes makes a difference but I can never remember which language it’s important in.

    This should get you a little closer:

    var date_id = 'fld-55a1678dc7b847f6be303140ad4779a3';
    var type_of_disbursement_id = 'fld-1214396547f84c9b8fcccac7917e0147';
    var unit_price_id = 'fld-8af21853bb8949bbbac92a1919fb5597';
    var number_id = 'fld-0616ad94503b4bd1b87bd4a1b0ce9d44';
    var date_requested;
    var type_of_disbursement;
    var unit_price;
    // var number;
    // var other_field;
    var number;
    var numbers = ['1', '2', '3', '4', '5'];
    
    var output = function printOut(continued) {
           if (continued == true) {
    	   console.log(date_requested + ", " + type_of_disbursement + ", " + unit_price + ", " + number);
    	   let newRecord = form.addNewRecord();
    	   newRecord.setFieldValue(type_of_disbursement_id,type_of_disbursement);
    	   newRecord.setFieldValue(unit_price_id,unit_price);
    	   newRecord.setFieldValue(number_id,number);
    	   document.saveAllChanges();
           } else {
              console.log("Cancel button pressed.");
           }
    }
    
    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Cancel';
    prompter.continueButtonTitle = 'OK';
    prompter.addParameter('Date: ','date_requested')
    .addParameter('Type of Disbursement: ', 'type_of_disbursement')
    .addParameter('Unit Price: ', 'unit_price')
    .addParameter('Number: ', 'number', 'popup', numbers)
    .show('Enter the type of disbursement, unit price and number wanted', output);
    #44390
    Victor Warner
    Participant

    I am trying to learn how to the use Prompter command/function. I have created a simple form script using the Prompter class, and added what I believe are the correct commands to save the output. But on running the script it is not saving the output to the fields of a blank record.

    The form script:

    var date_id = 'fld-55a1678dc7b847f6be303140ad4779a3';
    var type_of_disbursement_id = 'fld-1214396547f84c9b8fcccac7917e0147';
    var unit_price_id = 'fld-8af21853bb8949bbbac92a1919fb5597';
    var number_id = 'fld-0616ad94503b4bd1b87bd4a1b0ce9d44';
    
    var output = function printOut(continued) {
           if (continued == true) {
    	   console.log(date_requested + ", " + type_of_disbursement + ", " + unit_price + ", " + number);
           } else {
              console.log("Cancel button pressed.");
           }
    }
    var date_requested;
    var type_of_disbursement;
    var unit_price;
    // var number;
    // var other_field;
    var number;
    var numbers = ['1', '2', '3', '4', '5'];
    
    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Cancel';
    prompter.continueButtonTitle = 'OK';
    prompter.addParameter('Date: ','date_requested')
    .addParameter('Type of Disbursement: ', 'type_of_disbursement')
    .addParameter('Unit Price: ', 'unit_price')
    .addParameter('Number: ', 'number', 'popup', numbers)
    .show('Enter the type of disbursement, unit price and number wanted', output);
    
    record.setFieldValue(type_of_disbursement_id,type_of_disbursement);
    record.setFieldValue(unit_price_id,unit_price);
    record.setFieldValue(number_id,number);
    
    document.saveAllChanges();

    The Form is attached, with the form script (‘Prompt’)

    Also what commands would I need to add to create a new record before populating the fields with the output of the running the prompter?

    Any help would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    #44385
    Sam Moffatt
    Participant

    Ok, so you’re starting with a form and you’re looking to denormalise some data out into a new structure. I’d probably personally use a form script to do the heavy lifting during a data migration but I think what will work best for you is using the export functionality to export the set of records you want to put in the other forms and then reimport it.

    One thing is I suspect you’ll want to link these records once you split them apart. If you don’t have some sort of unique key for the records (student ID, client ID, etc), then I’d add one. A really quick way of doing it is to use a calculation field with the function UUID() in it and make sure the type is “Text”. That’ll give you a unique ID so that we can join it later. This might be unnecessary but I change the type to text once it’s generated since I don’t intend to keep using this field.

    Next step is to export the records and fields, including our unique field. If you want to export a subset, you’ll need to do a saved search to filter out the ones you’re interested in (should be a funnel icon on the top right next to the search box). If you do File > Export > Records then you’ll get a dialog where you can select the fields you want to bring to your new form. Don’t tick “Export record ID” and “Export linked records” but you will want to tick “Field type tags” and “Export media”. Hit Export and select a folder to send the export the files. You’ll get a CSV file created with a folder full of images to use.

    Next step is to import them into your new form. File > Import > Records will let you import to an existing form or even create a new form for you. Choose the CSV file that we just created and then choose the photo folder it would have exported (if you exported a photo field). I always tick the “add missing fields to form” option even though TF should match the field names automatically, it’s useful to have the extra field to understand what went wrong.

    That should populate your other form with a bunch of records (yay) though they’re obviously not inherently connected to your old records (boo!). Make sure everything is where you expect it to be though nothing should change (famous last words). This is where the “Link to Form” field type in “JOIN” mode helps us out. Add it to your main form, where it has “Link to Form”, select your target form, click on “JOIN” and then pick the unique ID field (either one you had already or the one just created) and Tap Forms will link those records together for you.

    I’d also created a second link to form field with the link type that makes sense for you (either one to many or many to many) so that moving forward you use this field to link the data together. The JOIN field requires both records share a common value and in the long run when you’re not importing data that’s a bit of work. Creating a TF managed link to form field will handle creating the linking metadata between the records for you with some extra UI functionality for picking records, creating them and a bunch more. You can use a script to automate migrating the JOIN’d records, do it manually, or just leave the JOIN field in place and update as you go.

    That should enable you to export your data and import it to new forms relatively easily, perhaps not quite as easy as drag and drop but I don’t think it’s an insurmountable problem.

    I have a video on leveraging link to form fields that might help you out as well as it covers a couple of different use cases. My channel has a few different videos that might give you some ideas on how you can model your data and make good use of Tap Forms.

Viewing 15 results - 1,276 through 1,290 (of 2,952 total)