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,251 through 2,265 (of 2,950 total)
  • Author
    Search Results
  • #37639

    In reply to: Scripting Time fields

    Martin Inchley
    Participant

    I’m in the UK, and my Mac’s Date/Time is set to auto, which means GMT currently.

    Getting the time calculation right in this database is crucial, because the info will be exported to tell musicians what time to turn up for a gig! I look forward to seeing how you folks resolve these problems (opportunities!).

    So, related to this question – in fact the reason why I went down this path in the first place – is the issue of how you combine info from a Time field and a Date field to produce a Date
    object that can be entered into a Date & Time Field. I’ve tried all sorts of JavaScript instructions, but TapForms doesn’t recognise any of the results as a valid Date-Time that can be used to set a field. Is there a simple method? – something I’m missing, please.

    #37626

    In reply to: Scripting Time fields

    Daniel Leu
    Participant

    It shows 11:06:26 AM for me and the script reports Thu Jan 01 1970 11:06:26 GMT-0800 (PST).

    At a first glance this is okay, but the console reports PST instead of PDT. PDT is UTC -7. Now I’m confused too…

    Cheers, Daniel

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

    #37620

    In reply to: Scripting Time fields

    Martin Inchley
    Participant

    Thanks, Brendan.

    I’ve just created a new document – one form, one (Time) field, one script

    I used the field time tool to enter the current time (20:06:26).
    Running the script gave me a console output of “Thu Jan 01 1970 19:06:26 GMT+0000 (GMT)
    “, which is one hour before the field value.

    Document attached. I’d really like to know what’s going on!

    Attachments:
    You must be logged in to view attached files.
    #37618

    In reply to: Scripting Time fields

    Brendan
    Keymaster

    Time fields always set the date portion to 0 time, which is January 1, 1970. But your time zone can definitely change how that appears.

    When I added a script to get the time, this is what I get when I log to the console:

    Thu Jan 01 1970 12:41:38 GMT-0700 (MST)

    I had entered 12:41:38 PM into the field.

    The output of your script:

    function Time_Script() {
    
    	var time = record.getFieldValue('fld-58b1679f309d4e848f3aaf8f1d22da45');
    	if (time) {
    		console.log(time);
    		
    		var thisHour = time.getHours();
    		var thisMinute = time.getMinutes();
    
    		var newTime = thisHour + ":" + thisMinute;
    
    		console.log(newTime);
    
    	}
    
    }
    
    Time_Script();

    for me was:

    Thu Jan 01 1970 12:41:38 GMT-0700 (MST)
    12:41

    So the same time values.

    #37615

    In reply to: Scripting Time fields

    Martin Inchley
    Participant

    Daniel,

    I should, of course, have checked this first. The answer is that console.log(thisTime) reports “Wed Dec 31 1969 23:14:00 GMT+0000 (GMT)”. So the issue is with the first step (extracting the data from the Time field), not with the getHours() function.

    To be sure, I’ve just created a completely new Form, with one record, one field, and one script:

    var thisTime = record.getFieldValue('fld-7c2e0886dfa54aa59ffb75012ddd49b1');
    console.log(thisTime)

    I used the time tool attached to the field to enter the current time (17:22:50). Running the script output Thu Jan 01 1970 16:22:50 GMT+0000 (GMT) to the console.

    #37604
    Sam Moffatt
    Participant

    If you are pulling from a JOIN field, you need to get the records in that JOIN. JOIN is a many to many type so you will get multiple records back:

    var joinRecords = record.getFieldValue('fld-nameofjoinfield');

    This will return you a list of records that you need to iterate over. If you look in the snippet editor there is a “child records loop” snippet that should help you if you select the field you care about and then do something useful with it.

    Depending on your use case, the result of last line of your script field will be used as the script field value. If you’re looking to pull values out then you can just leave a line with the variable in it that you want to show up in the field.

    Here’s an example of how you can combine multiple values from child Link to Form fields into a single value, this feels like it might be pertinent to your use case.

    #37600

    In reply to: record or records ?

    Marcus
    Participant

    @Daniel: I would not expect it as well, but it is the case
    Just tested in a testform again:

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

    This script will detect res as undefined in a listview, what is normal.
    Opening one recordset and going back to the listview the script will show the field value of the last opened record.

    Means, record is not blank once opened a record and switch back to the listview.

    Possible this is only on iOS the case, but for me it’s a bug.

    @Brendan ?

    #37596

    In reply to: record or records ?

    Sam Moffatt
    Participant

    Yah, if you’re in the list view then record is empty because you don’t have a record selected. On the desktop this is less of an issue because it’s very hard to never have a record selected but on iOS if you’re inside a pure list view record is blank. I’ve been caught by that before on iOS by running scripts from a list and getting a pop up reminding me I need to be inside a record.

    #37585
    Martin Inchley
    Participant

    I need to manipulate Time data in scripts. One problem is that when I use the JavaScript getHours() function, it subtracts an hour from the value in the field.

    var thisTime = record.getFieldValue('fld-95075cb1f5604be59afbc73094591e7a');
    var thisHour = thisTime.getHours();
    var thisMinute = thisTime.getMinutes();
    
    var newTime = thisHour + ":" + thisMinute;
    
    console.log(newTime);

    The field is showing 00:14. The console result is 23:14.

    I’m in a GMT zone, and the Mac’s Date & Time settings are on auto.

    Does anyone have an explanation / solution, please?

    #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?

Viewing 15 results - 2,251 through 2,265 (of 2,950 total)