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,776 through 2,790 (of 3,049 total)
  • Author
    Search Results
  • #31472
    Brendan
    Keymaster

    Did you use your own ID value for the rating_id field? Or did you just copy and paste and try to run the script?

    Did you get any error messages in the console log?

    I’m glad the other way worked for you at least.

    Thanks,

    Brendan

    #31463
    Andy Rawlins
    Participant

    Great, thanks Brendan. I couldn’t get the script to work – it didn’t seem to do anything but I was probably doing it wrong. However, the find and replace worked a treat so thanks for that :)

    #31453
    Brendan
    Keymaster

    By the way, to write the above script I only had to mostly just double-click on the various snippets in the Snippets list. The only thing I had to do was change the default variable name in the snippets. And this line of code I typed in: var aRecord = records[index];

    #31452
    Brendan
    Keymaster

    Hi Andy,

    You could definitely write a Form Script to do this. Or you could also use the Advanced Find & Replace function to do this. I’d make a backup of your document first whatever you do though.

    With the Find & Replace method you could start with searching the Rating field for 5, then set the value to 10. Then search for 4 and set the value to 8, then search for 3 and set it to 6, then 2 setting it to 4, then 1 setting it to 2.

    You have to do it in reverse as described above because if you go the other way, you’ll end up changing values you already changed.

    Or here’s a Form Script you can use for it:

    var rating_id = 'fld-3baff54c8e164de9b9ad3f0fbb040bc6';
    var records = form.getRecords();
    for (var index = 0, count = records.length; index < count; index++){
    	var aRecord = records[index];
    	var rating = aRecord.getFieldValue(rating_id);
    	aRecord.setFieldValue(rating_id, rating * 2);
    }
    form.saveAllChanges();

    You need to use your own rating field ID though (e.g. ‘fld-…..’). The above is specifically for my test form.

    But make sure you run it only 1 time otherwise you’ll double the rating values again.

    #31445
    Andy Rawlins
    Participant

    Hello

    My databases were imported from Bento. I have a rating field in most of my forms which are all 0-5 stars, because that is what Bento provided. I would like to make them 0-10 stars which I can do in Tap Forms but this means changing all the existing values: I have thousands of records.

    Is there a way to automatically double the ratings value in all records please? I have looked at scripts and at this forum but can’t find anything obvious that would do it. The closest I could manage was to make a new calculation field that takes the existing rating and doubles it. However, this does not allow me to enter data directly so it would not enable me to have a rating of say 7 because I can’t enter 3.5 in the original.

    Many thanks

    Andy

    #31282
    Brendan
    Keymaster

    Hi Izzy,

    Since 2011 I’ve added many new features to Tap Forms (the original post year). One thing you can do now is you can add a Script field which can process the value from another field in your form to do some manipulation of the values.

    So you could write a small script that removes any occurrence of the word “The” in the movie, book, or song title and returns that in the Script field. Then you can sort your records on the Script field values.

    Here’s a script that will do just that:

    var movie_title = record.getFieldValue('fld-987c9aac738a4f0fa1d18395902b3fb1');
    
    if (movie_title.startsWith('The ')) {
    	movie_title.replace('The ', '');
    } else {
    	movie_title;
    }

    So it will search for the first occurrence of ‘The ‘ and replace it with nothing, effectively removing it. And the if statement checks to make sure it only does that if ‘The ‘ appears at the beginning of the movie title.

    Hope that helps!

    Brendan

    #31065
    Daniel Leu
    Participant

    Hi Brendan,

    I try to assign the current date to a field using a script.

    First try:

    theRec.setFieldValue(date_sold_id, Date());

    Doesn’t show anything. If I change date_sold to a text field it works. Then I tried to get the date number:


    theRec.setFieldValue(date_sold_id, Date.parse(Date()));

    Doesn’t work either. But something like this works:


    theRec.setFieldValue(date_sold_id, theRec.getFieldValue(date_modified_id));

    When using a script, how can I assign the current date to a field? Thanks!

    — Daniel

    Cheers, Daniel

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

    #31024
    Martin Kendall
    Participant

    Hi,

    I’m still trying to think of ideas to get from drafts app to Tap Forms.

    I recently asked if the Tap Forms JavaScript had access to the clipboard (think of using that as the communications channel), but it hasn’t.

    I am now wondering if it is possible to paste records into the iOS version? I could make a drafts action create the correct format for the paste.

    Thanks

    Martin

    Daan
    Participant

    Brendan, I have one more question. The form.addNewRecord() function creates a new record but does not set any fields with default values specified. Eg I have a dateLeft field defaulting to today’s date; same with timeLeft defaulting to the time the new record is added.

    Is there either a way to create a new record with all field defaults applied, or do this in the script? (I do not exactly know what the actual values of those TapForms date and time fields are, so I also do not know how to setFieldValue them…)

    #31011
    John Mathew
    Participant

    Hi y’all,

    Am trying to use cloudant for syncing my database. Have followed the instruction re setting up an account, but I’m not sure where to find the password.

    This is the alphabet soup I get from the “credentials” on the cloudant site:

    {
    “apikey”: “1ZQdMj162xdk3vf4N0ZMkQAhN4oikS2z5-xCd-SXAAIX”,
    “iam_apikey_description”: “Auto generated apikey during resource-key operation for Instance – crn:v1:bluemix:public:cloudantnosqldb:eu-gb:a/6573add2f18f4d48b22620fd392dd094:32191e04-2a8b-4bbe-bc54-bff77190292f::”,
    “iam_apikey_name”: “auto-generated-apikey-36ca775e-c28c-425c-bf55-4f5754841a8a”,
    “iam_role_crn”: “crn:v1:bluemix:public:iam::::serviceRole:Manager”,
    “iam_serviceid_crn”: “crn:v1:bluemix:public:iam-identity::a/6573add2f18f4d48b22620fd392dd094::serviceid:ServiceId-2432e2f3-f9ba-4cc1-be44-15a42d4bc426”,
    “url”: “https://2dc42a4a-07a3-405f-91f6-66fbe35a4cdd-bluemix.cloudant.com&#8221;,
    “username”: “2dc42a4a-07a3-405f-91f6-66fbe35a4cdd-bluemix”
    }

    The username is pretty apparent, but I have no idea what the password is. Can anyone help?

    Many thanks in advance.

    #30998
    Brendan
    Keymaster

    I created a mileage tracker form but posted it in the regular forum. Figured I should post it here for everyone to download. It requires Tap Forms 5.3 at a minimum because it uses JavaScript to copy the previous mileage value to a new record. You need to select a record and then run the script. Tap Forms will create a new record and copy over the values from the selected record to the new record.

    Use the Import Tap Forms Archive function to import this file.

    Thanks!

    Brendan

    Attachments:
    You must be logged in to view attached files.
    Daniel Leu
    Participant

    Hi Brandon,

    Cool! Didn’t think of that at all.

    When I run it in the ‘edit script’ view, the result is shown in the Results field. I would expect to see this in the Title field in the Layout View too, but that remains empty.

    Sorry for all the beginners questions!

    Thanks!

    – Daniel

    Cheers, Daniel

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

    #30984
    Brendan
    Keymaster

    Yup. You’re right. I’ve just made a change to fix this so it will do what it’s supposed to do. The Mac version was just calling the wrong code that wasn’t evaluating the script only for those fields that were referenced in it. But the next update will behave that way.

    Daniel Leu
    Participant

    Hi

    I have the parent database “Photo Database” with the child “Photo Prints”. The child database is used to keep track of all prints created and sold. In there, I would like to include some basic information from the parent database such as image title.

    In the parent database I set the one-to-many link and enabled show inverse relationship. Then in the child database I created a field with the type ‘script’ containing


    var image_title = photo_database.getFieldValue('fld-a64a1b71aeb8408499143d9c852b0056');
    image_title;

    But when I run it, following error:


    ReferenceError: Can't find variable: photo_database, column:33, line:1

    I guess I’m missing something to define photo_database which is the parent “Photo Database”. Attached is the sample template. Thank you for your help!

    – Daniel

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

    Cheers, Daniel

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

    #30981
    Martin Kendall
    Participant

    I’ve done a bit more investigating.

    In the script editor (on the Mac) after saving and then reopening it, there is a check mark against the A field and none of the others. So the script is doing the clever bit (knowing that it should only run on changes to A), but it appears to run on changes to any field.

    I’m using Tap Forms 5.3.2 on the Mac.

    I’ve now just checked on my iPad and iPhone and the script, correctly, only updates on changes to A. So perhaps it is a bug in the Mac version?

Viewing 15 results - 2,776 through 2,790 (of 3,049 total)