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,296 through 2,310 (of 2,986 total)
  • Author
    Search Results
  • #37581
    Simon Inchley
    Participant

    I want to put into a field a value from a field in a related record. I’ve defined the relationship as a “join”, based on a different field in each form, and for present purposes it doesn’t matter to me which of the forms is the parent and which the chid. I’ve written a really basic script, where the target field is called “Test Field” and the field in the related record from which I want to get the info is called “Line Up”:

    var test_field_id = ‘fld-49c13a65b1324a92941d51a895526d06’;
    var line_up = record.getFieldValue(‘fld-ece13baf855a423cb121bfde1167f1b4’);

    record.setFieldValue(test_field_id, line_up);
    form.saveAllChanges();

    console.log(line_up);

    Nothing appears in the target field, and the console entry reads “undefined”.

    Can TapForms perform this operation?

    #37577

    In reply to: record or records ?

    Daniel Leu
    Participant

    Oh… I’m mainly on the desktop. Maybe adding a check if record is undefined could be used to avoid fetching a value of an undefined record.

    I have several scripts that operate on the current record or on all records. I use the prompter to select the desired operation.

    Cheers, Daniel

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

    #37575
    Daniel Leu
    Participant

    I’m missing an API refresh call as well. I have asked for record.refresh(), form.refresh(), search.refresh(). Hopefully one day we’ll get something like that.

    In my testing, scripts are not executed upon record creation. I have created a testcase for Brendan to review. I would assume that this is related to what you see.

    Cheers, Daniel

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

    #37570

    In reply to: record or records ?

    Marcus
    Participant

    Really confusing, but thanks so far.

    I do not have a script field,
    but scripts to be executed manually.

    I thought there‘s s easy way to detect
    if I‘m in „listview“ or in „record view“.

    Isn’t this a bug ?
    Executing this script in „Listview“:

    
    function Test2() {
    res=record.getFieldValue('fld-76b2c64fccc34c20b62b7d485f5bfa28');
    return res;
    }
    
    Test2();
    

    Will cause this error:

    Test2: TypeError: undefined is not an object (evaluating ‘record.getFieldValue’), column:12, line:3

    Opening a record and go back to the listview
    will then show the value of the last opened record,
    which is closed…
    Look like this happens only when a filter is active.

    #37556

    In reply to: record or records ?

    Sam Moffatt
    Participant

    I’m not sure I understand what you mean so let me see if I can meet you half way to figure this out.

    My guess is you have either a form script you run manually or a field script somewhere that is connected to a field in your parent form. I’m also guessing you have another field script that is connected to a field either in the same form or maybe a child form.

    When your first script runs (either manually as a form script or in response to a field it watches changing), you end up in a situation where the other script is running. Form scripts are fun in that they can execute without record being set which can lead to interesting situations if you don’t expect that, that could be the first source of your problem.

    If your first script does a setFieldValue on a field that the second script is watching, it will trigger the second script to run. There is a third variable for setFieldValue which you can set to false or zero that will prevent scripts from running when the value of that field changes. The second script I believe is executed in the same Javascript context as the first which means variables can be shared between them. Variables like record is a special variable and I’m not sure what it would be in the context of a child record. However for scripts within the same form, in my experience they quite often share the same Javascript context.

    Because they share the same Javascript context, any variables you assign in the first script will be available to the second script and any variable that was defined in the first script you alter in the second script will change the value in the first script.

    A simple example could be that you use records in your first script and then also use records in the second script. If that second script is triggered based on a setFieldValue in the first script, then the next line after the setFieldValue in the first script will have the value of records from the second script. If you’re dealing with loops this can result in all sorts of odd behaviours with records you don’t expect showing up.

    This is really confusingly written however unfortunately I don’t know how to simply explain it. I hope this makes sense and maybe is applicable for your use case. Let us know if it does or doesn’t help you so we can figure out the path forward :)

    #37545
    Martin Inchley
    Participant

    Having checked out TapForms’ AppleScript dictionary, I wrote the following:

    tell application “Tap Forms Mac 5”
    run form script named “Composite script” in form “New gig database”
    end tell

    The script compiles OK, but when I run it I get an error: “Tap Forms Mac 5 got an error: Can’t get form script \”Composite script\”.” number -1728 from form script “Composite script”.

    The TapForms form script “Composite script” itself is alive and well and functioning fine in the database, so it’s likely to be an issue with how instructions work. I couldn’t find any examples of AppleScript calling a TapForms script, neither in the forum nor in the wider net. Anyone know how to do this?

    #37539
    Brendan
    Keymaster

    Hi Federico,

    If you have a one-to-many relationship from Customer to Appliance then yes you can do this easily.

    Make sure you set the Show Inverse Relationship option on your Link to Form field, then Tap Forms will show the parent relationship on the Appliance form.

    However, once you’ve done that, you can pick out values from specific parent fields just by adding a Calculation field that references a field from the parent. Just make sure you set the Return Type to be the correct type. If it’s the name of the contact, then it’s probably Text.

    You can also use a Script field for the same purpose.

    Thanks,

    Brendan

    #37537
    Federico Santello
    Participant

    Hello everyone.
    I have a question.
    I have a form for customer, each customer can have multiple appliance and i Have create a child form where i put the appliance.
    In the child form i want that some field as name of the customer and address will be filled automatically from the customer form.
    How can i do?
    I need Java script?
    Someone can help me with the script?

    Thank’s
    Federico

    #37535

    In reply to: record or records ?

    Marcus
    Participant

    Let did not solve it.

    How to explain ?
    I do have a form with a lot of repeating fields.
    Name1
    Date1
    Task1

    Name2
    Date2
    Task2

    Name3
    Date3
    Task3

    A script will look for the next empty date,
    will set a date, name and task.

    This script is executed when a recordset is open.

    Another script will be executed as „clean up“,
    remove expired recordsets by date.

    My goal is to prevent the execution of a script in the wrong view.

    There are differences between a loop over all recordsets
    or just the current visible record.

    #37530
    Daniel Leu
    Participant

    You can use standard Javascript date and time functions for this: https://www.w3schools.com/jsref/jsref_obj_date.asp:

    var date_id = 'fld-xxxx';
    
    var d = record.getFieldValue(date_id);
    console.log(d.toLocaleTimeString());

    Cheers, Daniel

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

    #37529
    Martin Inchley
    Participant

    I’m writing a script to concatenate info from lots of fields, including a Time field, and insert it into a Notes field. The line with data from the Time field includes the date 1st Jan, 1970, before the time. I need it to include the time of day, and no date.

    #37484
    Sam Moffatt
    Participant

    The Script Editor has a field list on the left that will let you insert snippets with the field ID’s populated for you, either assigning the ID to a variable or creating a line that pulls the value from the field in one step. If you have linked forms, it’ll also include the fields from those as well. It’s not quite as visually smooth as the calculation editor but I think it’s a pretty reasonable compromise to support scripting in Tap Forms.

    #37481
    Daniel Leu
    Participant

    Changing the name of a field doesn’t require changes to the script as long as you use the field id instead of the field name.

    Cheers, Daniel

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

    #37477
    Eddy
    Participant

    Hi Sam!

    Thanks for this advice.

    Actually I already thought about that, but…
    if I use the calculation field, the names of the field I am using in a formula seem to be updated/actualized, whenever I change the name of a field. Yes, of course you can say, it is not the clean way to change field names, but this is what I have to do sometimes, as long as I develop.

    What I am wondering about is that: If you need a line break in the calculation field, you have to insert “\r”. So, obviously there is something like an escape code. So, how can I box special characters with an escape code? I think, I just have to learn, which coding for the characters is nessesary. Obviosly, it’s not like in java/javascript, because this I tried already…

    Regards, Eddy

    #37475
    Sam Moffatt
    Participant

    Try using a script field instead of a calculation field. Script fields use Javascript and are a little more lenient. It’s slightly more code but a lot more powerful. Any time I go beyond a basic calculation I jump over to a script field, easier to debug and update.

Viewing 15 results - 2,296 through 2,310 (of 2,986 total)