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 - 2,521 through 2,535 (of 2,864 total)
  • Author
    Search Results
  • #33253
    Brendan
    Keymaster

    You want a Script field just as you’ve created. Because you’re wanting to display the first passport information in the parent form.

    Here’s the exact script you can just copy and paste into your Passport Script:

    // declare the field ID for the passport field. Select the field and click the ID button to get the field ID.
    var passport_id = 'fld-bb12ade9886146818f0cee47af4a36d5';
    
    var result = '';
    
    // From the currently selected record, get the list of records from the passport field.
    var passportRecords = record.getFieldValue(passport_id);
    
    // if we have any passport records, get the passport information.
    if (passportRecords.length > 0) {
    
       // Get the very first passport record from the list of passportRecords.
       var firstPassportRecord = passportRecords[0];
    
       // declare the passport field ids.
       var passport_number_id = 'fld-fc5f7b08aa244466919fd400714ffa6b';
       var date_of_expiry_id = 'fld-b73ebd82a8b2479882e9d2fc5b161ff9';
       var country_id = 'fld-b502438543564135859a133912994d3f';
    
       // From the first passport record we grabbed above, get the passport number value.
       var number = firstPassportRecord.getFieldValue(passport_number_id);
       var expiryDate = firstPassportRecord.getFieldValue(date_of_expiry_id);
       var country = firstPassportRecord.getFieldValue(country_id);
    
       // and do whatever you want with the values. What you had is almost what you needed:
      
      result =   "having a " + country + " passport, with a date of expiry of " + expiryDate.toLocaleDateString() + " and a passport number " + number;
    
     }
     
     result;
    
    #33238
    Victor Warner
    Participant

    Brendan,

    Thank you very much for explaining the script, and I can now understand the logic of it but I am having difficulty applying it my database.

    As being completely new I am still not clear whether I should be creating

    1. a new field of the type script; or
    2. a Form script

    If a new field script, should I creating a field in the Client Contact form or the Passport form?

    Attached is a backed up version of the Forms to show how it actually looks.

    Attachments:
    You must be logged in to view attached files.
    #33210
    Victor Warner
    Participant

    Brendan,

    Thank you for the reply.

    As I mentioned Javascript is unknown me (but it is clear I will have to learn it), but in the meantime I wonder if you could provide some explanation for each of the lines of code you provided (to try to understand how to relate the code to the example I gave in my initial post):

    var passport_field_id = ‘fld-….’;
    var passportRecords = record.getFieldValue(passport_field_id);
    if (passportRecords.length > 0) {
    var firstPassportRecord = passportRecords[0];
    var number_field_id = ‘fld….’;
    var number = firstPassportRecord.getFieldValue(number_field_id);

    // and do whatever you want with the values/

    }

    And I in particular how I write the code for

    // and do whatever you want with the values/

    if I wished to produce:

    “having a ” + [country] + ” passport, with a date of expiry of ” + [date of expiry] + ” and a passport number + ” ” [passport number]

    Any help you could provide would be very gratefully received.

    #33134
    Brendan
    Keymaster

    Yes, it would have to be a Script Field and not a Form Script. That’s because Form Scripts all are run manually whereas a Script Field is run when a value it references changes.

    yes, the record.getFieldValue(field_id) reference is what tells Tap Forms that script is referencing that field, so when that field changes its value, run the script that references it.

    #33132
    Brendan
    Keymaster

    I’ve changed things for the next update with respect to editing scripts. No matter where you edit a script from in the next update, Tap Forms will go full screen for the editor. So there will be no chance of accidentally switching records and losing your script contents.

    #33130
    Brendan
    Keymaster

    It’s best to declare variables within a function declaration.

    function runPrompter() {
       var upc_lookup_id = 'fld-8b5f99cd185044f8a0b35204db4c86ac';
       record.getFieldValue(upc_lookup_id);
    
       var callbackFunction = function() {
    	console.log(value_1);
       };
    
       var value_1;
       let prompter = Prompter.new();
       prompter.addParameter('Label 1').show('Message prompt', callbackFunction);
       record.setFieldValue(upc_lookup_id, false);
       document.saveAllChanges();
    }
    
    runPrompter();

    That should work.

    But it may be that you’ve found a bug that’s not clearing out the JSContext when you run the script the second time.

    Also probably that I haven’t tested the prompter within a Script Field. I’ve only ever used it within a Form Script.

    #33125
    Ian Heath
    Participant

    What is the recommendation in relation to declaration of variables in scripts?

    I have a test/demo field script which is executed every time a check mark is changed.

    The problem I have is when this is run for the 2nd and subsequent times I get an error since the variable is already declared (see error on screenshot attached).

    
    var upc_lookup_id = 'fld-8b5f99cd185044f8a0b35204db4c86ac';
    record.getFieldValue(upc_lookup_id);
    var callbackFunction = function() {
    	console.log(value_1);
    };
    var value_1;
    let prompter = Prompter.new();
    prompter.addParameter('Label 1')
    .show('Message prompt', callbackFunction);
    record.setFieldValue(upc_lookup_id, false);
    document.saveAllChanges();
    

    It’s entirely possible I’m doing something daft since I’m new to javascript!

    Attachments:
    You must be logged in to view attached files.
    #33123
    Ian Heath
    Participant

    Fixed it, I was using a form script not a field script (assume it has to be the latter?).

    Also I didn’t have this line in the script which I think is needed?

    record.getFieldValue(upc_lookup_id);

    Thanks

    #33118
    Ian Heath
    Participant

    Just noticed a minor issue I think. If I’m editing a script and don’t save it then change the view on the left hand navigation then there’s no warning and my changes are lost. However if I navigate away using the right hand pane then I do get a warning.

    Example in image (green gives warning, red does not).

    Attachments:
    You must be logged in to view attached files.
    #33116
    Ian Heath
    Participant

    Ah that’s an excellent idea. I tried it and it’s not working though, no-doubt an issue with me.

    I have a Form Script with a reference to the check mark field in it:

    var upc_lookup_id = ‘fld-8b5f99cd185044f8a0b35204db4c86ac’;

    Which I assumed was sufficient to trigger the script when that field is updated?

    Assume I’m missing something :-)

    #33109
    Brendan
    Keymaster

    Well, with a Link to Form field, there’s no way in a Calculation field to reference an individual child record. So the only way to do it is to use JavaScript.

    Going the other way was just a suggestion.

    #33108
    Brendan
    Keymaster

    Well, you could simulate a button by adding a Checkmark field to your form and then reference that Checkmark field in your script. When you tap the Checkmark field, the script will run.

    #33102
    Victor Warner
    Participant

    Brendan,

    Thank you for the reply.

    The script example, unfortunately, is beyond me (having no knowledge of JavaScript) at present.

    I am not sure that I understand, fully, the following:

    “then you could add a Calculation field to your Passports form that references the Client Contact data. In that situation because it’s as One-to-Many relationship, the inverse of that is a Many-to-One and you can reference individual fields from the one Client Contact record from within the Passport records.”

    These seems to be suggesting the reverse what I am seeking.

    I am not seeking to reference individual fields from the Client Contact record, but rather, the reverse, some fields from one of the records in the Passport form.

    As I am new to Tap Forms I suspect I am missing something – further help would be greatly appreciated.

    #33101
    Ian Heath
    Participant

    Any plans to add this to iOS versions, or if not layouts at least a simple button option in place of a field to trigger a given script. I think that’d be a great enhancement.

    Cheers Ian

    #33094
    Brendan
    Keymaster

    Oh yes. That’s right. Sorry about that. Custom layouts are only available on macOS and that’s why there’s no button function in the iOS version. You have to use the Run Script menu to activate a Form Script on iOS.

Viewing 15 results - 2,521 through 2,535 (of 2,864 total)