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,146 through 2,160 (of 2,953 total)
  • Author
    Search Results
  • #38253
    Martin Inchley
    Participant

    I have a checkbox field “Paid”, and a date field “Payment Date”, with their interactions controlled by two script fields. Checking or unchecking “Paid” enters the current date in “Payment Date”, or empties it. Manually entering a date in “Payment Date” checks “Paid”. Deleting the date unchecks “Paid”. Editing the date leaves it alone.

    Everything works fine on their own form. Issues arise when I access them through a Link-to-Form field in another form. Some of the behaviour is consistent, some not. One particular oddity is this:

    Accessing these records via the Link-to-Form field, editing the date field results in the checkbox being unchecked, which shouldn’t happen. But when I go to the native form I find that the checkbox is still checked. Back to the linked form – the box is certainly unchecked there.

    So my investigation of how to get the scripting to work across forms is hampered by this anomaly. Is the box checked or not? I’d appreciate some advice on how to approach this problem.

    Here are the scripts from the control fields, in case they shed any light on things:

    //Responds to the "Paid" checkbox field being toggled, 
    //by setting or emptying the Payment Date field
    
    var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144';
    var paid = record.getFieldValue(paid_id);
    
    var thisDate = new Date(); // put the current date into <thisdate>
    
    if (paid) {
        
    // Use a special version of "setFieldValue" to prevent triggering the Toggle script
        record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', thisDate, false);
    } else {
        record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', "", false);
    }
    //Responds to the "Payment Date" field getting an entry or being emptied, 
    //by toggling the "Paid" checkbox field
    
    var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b';
    var payment_date = record.getFieldValue(payment_date_id);
    
    if (payment_date) {
        record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "true", false);
    } else {
        record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "false", false);
    }

    Any observations very welcome. And, just to note, clicking the refresh button seems to make no difference at any point.

    #38250
    Brendan
    Keymaster

    Can you email me your form template so I can examine it?

    The multi-column list views pick lists really only work properly with single-value Pick Lists. It’s probably something I should look into to see if I can get it to show multiple values at some point.

    There are certain field types that you can’t edit though, such as Calculation fields, Script fields, etc.

    Also, do you have access controls enabled and the form locked? That can prevent editing.

    #38227
    Eddy
    Participant

    Thanks Brendan, for your promt answer!

    I found a way to generate mails from Tapforms to MacOS by using Javascript.

    Like this:

    Mail = Application('com.apple.Mail')
    message = Mail.OutgoingMessage().make()
    message.visible = true
    message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" }))
    message.subject = "Testing JXA"
    message.content = "Foo bar baz"
    
    attachment = Mail.Attachment({ fileName: "/Users/myname/Desktop/test.pdf" })
    message.attachments.push(attachment)

    Or, even better by using the PATH-Command:

    Mail = Application('com.apple.Mail')
    message = Mail.OutgoingMessage().make()
    message.visible = true
    message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" }))
    message.subject = "Testing JXA"
    message.content = "Foo bar baz"
    
    attachment = Mail.Attachment({ fileName: Path("/Users/myname/Desktop/if the file has spaces in it test.pdf") })
    message.attachments.push(attachment)


    The question is now:
    How can I address the file / path inside Tapforms correctly?

    Thanks in advance:

    Eddy

    #38214
    Brendan
    Keymaster

    But also you could go into the Multi-Column List View mode, select all the values from one field, then click in the first cell of another field and paste. All the values will be pasted in order into the other field. Make a backup first in case it doesn’t do what you expect. Or the script that Sam posted.

    There’s also the Fill Down function too which can be used to fill a value from the selected cell into all the selected cell below it.

    #38209
    Sam Moffatt
    Participant

    Use the script editor to grab the two fields ID’s and their values. For your old field, if it has a set of values then you need to translate them to the new value. I’d use a switch statement here on your old field to map it over, something like:

    let oldValue = record.getFieldValue('fld-1234');
    let newValue = record.getFieldValue('fld-4321');
    
    switch(oldValue)
    {
      case 'Swimming':
         record.setFieldValue(newValue + ', swi1', 'fld-4321');
         break;
    }

    Then for your new field, if you have a multipick list then get the current value and then use JavaScript to append “, <new value>”. It’ll look a little weird ofr empty fields but shouldn’t hurt anything. If it is a single value pick list, then you can just reset the field value.

    If you create a form script, you can use form.getRecords to get all of the records and then process them one at a time. A pattern I use is to create a function script that accepts a record field and then label it as currentRecord to avoid getting confused in the scope. Then I can test using a single record or later on put it in a loop.

    #38198
    Martin Inchley
    Participant

    Good spot, Daniel!

    Unfortunately, adding it made no difference.:(

    And the other script that makes the value appear when I trigger it manually makes no difference when I call it from within my Script Field script.

    #38197
    Daniel Leu
    Participant

    I think you are missing a document.saveAllChanges(); at the end of the script.

    Cheers, Daniel

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

    #38196
    Martin Inchley
    Participant

    Late night extra extra:

    In this scenario, with the Paid box checked, the Calc field showing the Paid Date field is not empty, but the Paid Date field not actually showing anything – if I run a script to fetch the contents of the Paid Date field, the date suddenly shows up in it!

    Similarly when I’m emptying it – the emptying only shows when I run a script to get the contents (and, worryingly, occasionally not even then).

    Is this likely to be a time-lag in saving the data, or is there perhaps some trigger that’s not firing?

    #38194
    Martin Inchley
    Participant

    Extra evidence:

    Tinkering with this I set up a Calc field to hold 1 if the Payment Date field was not empty, and 0 if it was. After the Script field has been triggered by checking the Paid tick-box, this new Calc field is registering 1, even though the Payment Date field appears to have no content.

    There would appear to be something in it, stirring beneath the waters…

    #38193
    Martin Inchley
    Participant

    The following script is designed to put the current date into a Payment Date field when a Paid tick-box is checked.

    var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b';
    var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144';
    var paid = record.getFieldValue(paid_id);
    
    var thisDate = new Date();
     
    if (paid) {
    	console.log(thisDate);
    	record.setFieldValue(payment_date_id, thisDate);
    } else {
        console.log("no date");
        record.setFieldValue(payment_date_id, "");
    }

    When it’s run as a Form Script, it works fine. When it’s used within a Script Field, the console entries come in as usual, but the Date field doesn’t change, neither to get the Date nor to be emptied when unchecking the field.

    If I set the If section to show the output in the Script field itself:

    if (paid) {
    	console.log(thisDate);
    	thisDate;
    } else {
        console.log("no date");
        "";
    }

    the date appears and disappears as it should.

    Am I missing something in how Script fields execute actions?

    #38189
    Brendan
    Keymaster

    What do you mean by populate some of that info into the field Summary? So you don’t want the entire value from your Quick Glance field to be put into the Summary field? But only part of the field value?

    You could also write a Form Script to loop through your records, looking at field values from specific fields and populating your Summary field with whatever info you deem necessary.

    #38188
    Brendan
    Keymaster

    @Martin, that’s where the power of Scripting comes in. You can build scripts that expose the data further up the relationship chain from lower down. Although in general that’s a read-only thing. I agree though, it would be nice to be able to put editing controls in Tap Forms from anywhere down the relationship hierarchy. Doesn’t mean I’ll ever build that. But I understand the desire.

    #38178

    In reply to: Table row index number

    Sam Moffatt
    Participant

    I think the challenge is with a table field, the calculation field only displays the fields from the record context. If you try to copy a field placeholder from a parent calculation field into the table calculation field then it doesn’t save right. If you create a script field in the table, when you insert the fields in the editor it includes the index format (e.g. table_field_name[index]) and record in that scope is still the main record, getFieldValue for fields in the parent form work but don’t work for fields in the current row of the table.

    At least in my testing, I couldn’t figure out how to get it to behave correctly.

    #38169

    In reply to: Table row index number

    Brendan
    Keymaster

    Hi Stephen,

    I don’t think you need to index into this. Is your goal to do that simple multiplication, then all you need to do is add a Calculation field to your form that multiplies your Minutes field by your Hourly_Rate field.

    You can also do it in a script:

    function Cost() {
    	var minutes_id = 'fld-abcd1234...';
    	var hourly_rate_id = 'fld-1234abcd...';
    
    	var minutes = record.getFieldValue(minutes_id);
    	var hourly_rate = record.getFieldValue(hourly_rate_id);
    
    	return minutes * hourly_rate;
    }
    
    Cost();

    The value of record will be the current record in the Table field.

    #38168

    In reply to: Table row index number

    Sam Moffatt
    Participant

    Ok, so I had to read this a few times and I’m still not sure I understand correctly but I did do some testing. I think you’re trying to calculate a cost based on the value in the table field and a value in a field outside of the table field?

    I tried figuring out how to do this myself with a script field and couldn’t get it to work. I can sort of do it in a calculation field but only with fields from within the table. I might be missing something obvious, maybe I need to look later.

    If you’re willing to restructure a little, I think you can do what you want a little easier with a Link to Form field though the script/calculation field in the table should be able to do that.

Viewing 15 results - 2,146 through 2,160 (of 2,953 total)