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,416 through 2,430 (of 2,950 total)
  • Author
    Search Results
  • #36373
    Brendan
    Keymaster

    Did you get any syntax errors when running your script in the Script Editor?

    Make sure you don’t use curly quotes or curly apostrophes. That can cause things to fail.

    if (reward == ‘YES’ && over_15 == 10) {

    From what I can see, you’ve got curly apostrophes around YES. It should be:

    if (reward == 'YES' && over_15 == 10) {

    #36370
    Karl M. Rowe
    Participant

    Hi, Sam!

    “Do either of these sound like something closer to helping solve your problem?”

    I liked reading what you proposed as a way to go forward. I will be re-reading your post to make sure I didn’t miss anything, but on my first read-through, I wanted to see the code, to see how this would work.

    whatever reason I have been posting responses to the posts here much later than I would have otherwise, and the result is that I’m never sure when my posts have actually posted here. (One of my posts were stuck in the browser with an error message from your web server.)

    Let me ask you a simpler script question:

    Let’s say in a form you had the Checkboxes A!..A3 snd Checkboxes B1..B3, and when CBB1 and/or CBB2 and/or CBB3 is/are set to “1” (checked), then the CBA1, CBA2 and CBA3 checkboxes would be reset to “0” (unchecked), and only if CBB1 was set to “1” would the corresponding CBA1 would to set to “1” and CBB1 would be set to “0”; only if CBB2 was set to “1” would the corresponding CBA2 would to set to “1” and CBB2 would be set to “0”; and only if CBB3 was set to “1” would the corresponding CBA3 would to set to “1” and CBB3 would be set to “0.”

    What would such code look like? Would you use a “IF/ELSE” or a “FOR” loop to do this or something else altogether?

    I’m also interested in seeing your proposed script. Thanks.

    Peace

    #36368
    Karl M. Rowe
    Participant

    [This post was in my iPhone’s browser with an error since last week that I only just noticed, but for some reason it was never posted]

    Hi, Sam!

    “Why not record the purchase events and calculate how many purchases from there?”

    This database is being built for non-computer literate people, who would only be responsible for nothing purchases made and by whom; nothing more.

    The “admin” would note the purchases made daily and note the free items that would be awarded to eligible customers, snd reset the two sets of checkboxes in the database as required. Now I was given some sample code to use in a script, but I’ve no idea how to identify each of the checkboxes using the app, but this database isn’t something I would build for my use.

    Pesce

    #36367
    Karl M. Rowe
    Participant

    Hi, Sam and Brenden! i’m

    I appreciate your pointing out to me how I might use a script with my database to reset a set of checkboxes. I’d like to see a few examples of how such might be used. An example of an “Are you sure (y/n)?” prompt using Javascript is something I’d also be interested in seeing. Thanks for your reply.

    I wrote the following script that is designed to do a checkbox reset of the first set of checkboxes *only* when the “reward” field is equal to “YES,” and to use the number in the “over-15” field that represents the number of checked checkboxes in the second set of checkboxes to reset all of these checkboxes, but repopulate the reset first set of checkboxes with the number of checkboxes in the “Over-15” field, and afterward display a “Done!” prompt If the “reward” field is equal “no,’ the script should end without a checkbox reset at all.

    For example, if there are three checked checkboxes in the second set of checkboxes, the script would end with three checked checkboxes in the first set of checkboxes; if there is one checked checkbox in the second set of checkboxes, the script would end with one checked checkbox in the first set of checkboxes. Thanks for any help “you guys” might be able to provide me.

    The script, which doesn’t work, and may need to be discarded for a better one, is s follows:
    function Test2() {

    var f1_id = ‘fld-66cc9d4ad3c149c496cd3be90ea0f88c’;
    var f2_id = ‘fld-0dca226557ba47d2b806dd2f20d955ec’;
    var f3_id = ‘fld-e084b0d50e104044ab8baf2df11ae1e4’;
    var f4_id = ‘fld-6ee4490027334c8ea99f9e0365fef5f7’;
    var f5_id = ‘fld-b31757d2bda64dbfadf5fa3569857c33’;
    var f6_id = ‘fld-fbb171c0d7c14d90b5a248ea6baab1a9’;
    var f7_id = ‘fld-43a5c0ff16694eb19325b9c24dcaa2de’;
    var f8_id = ‘fld-4f1cbec2e2bd475b8a58badd20e66826’;
    var f9_id = ‘fld-9985de5176ac4861890a245c729e818a’;
    var f10_id = ‘fld-c5cf49dd9e954f18952e0eb7354f93aa’;
    var f11_id = ‘fld-49c502ea885342738df3ce1958d0542e’;
    var f12_id = ‘fld-22395b52e8a344e8b23499df65def764’;
    var f13_id = ‘fld-07b05a9ad759465abd4ffc436e74b11e’;
    var f14_id = ‘fld-6be47e6efbee473b9a725e67167dd90c’;
    var f15_id = ‘fld-d507eb4e113d4380b1ab5f2f20518e6c’;

    var fx1_id = ‘fld-e3cd7e31ec7541538b424b7dfbd51ae0’;
    var fx2_id = ‘fld-c98c294dffbc4f19a02dea33473df2c8’;
    var fx3_id = ‘fld-98c491b1011c430f9cdae91937c6c6d5’;
    var fx4_id = ‘fld-2fbadd9308b04c7ab0de74eeee1d5ef6’;
    var fx5_id = ‘fld-af079845162241559254c094021892d5’;
    var fx6_id = ‘fld-d864cc7f08154fc2bad5762f4d086f4f’;
    var fx7_id = ‘fld-e4797c4cbab44dc0be98495b18978c79’;
    var fx8_id = ‘fld-ba105d19a44e4cc59670df9c538b8992’;
    var fx9_id = ‘fld-488d0a66e8b04e62b71288305b00dff5’;
    var fx10_id = ‘fld-f96f1a34300b4a2ab2d7cd30f7801e69’;

    var over_15 = record.getFieldValue(‘fld-83370febd23045f6b839a9401cf598fd’);
    var reward = record.getFieldValue(‘fld-61bd01ed639d4166949dd3404d10036e’);

    record.setFieldValue(f1_id, 0);
    record.setFieldValue(f2_id, 0);
    record.setFieldValue(f3_id, 0);
    record.setFieldValue(f4_id, 0);
    record.setFieldValue(f5_id, 0);
    record.setFieldValue(f6_id, 0);
    record.setFieldValue(f7_id, 0);
    record.setFieldValue(f8_id, 0);
    record.setFieldValue(f9_id, 0);
    record.setFieldValue(f10_id, 0);
    record.setFieldValue(f11_id, 0);
    record.setFieldValue(f12_id, 0);
    record.setFieldValue(f13_id, 0);
    record.setFieldValue(f14_id, 0);
    record.setFieldValue(f15_id, 0);
    //record.setFieldValue(fx1_id, 1);
    //record.setFieldValue(fx2_id, 1);
    //record.setFieldValue(fx3_id, 1);
    //record.setFieldValue(fx4_id, 1);
    //record.setFieldValue(fx5_id, 1);
    //record.setFieldValue(fx6_id, 1);
    //record.setFieldValue(fx7_id, 1);
    //record.setFieldValue(fx8_id, 1);
    //record.setFieldValue(fx9_id, 1);
    //record.setFieldValue(fx10_id, 1);

    if (reward == ‘YES’ && over_15 == 1) {
    record.setFieldValue(f1_id, 1);
    record.setFieldValue(fx1_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 2) {
    record.setFieldValue(f2_id, 1);
    record.setFieldValue(fx2_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 3) {
    record.setFieldValue(f3_id, 1);
    record.setFieldValue(fx3_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 4) {
    record.setFieldValue(f4_id, 1);
    record.setFieldValue(fx4_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 5) {
    record.setFieldValue(f5_id, 1);
    record.setFieldValue(fx5_id, 0);
    } else

    if (reward == ‘YES’ && over_15 = 6) {
    record.setFieldValue(f6_id, 1);
    record.setFieldValue(fx6_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 7) {
    record.setFieldValue(f7_id, 1);
    record.setFieldValue(fx7_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 8) {
    record.setFieldValue(f8_id, 1);
    record.setFieldValue(fx8_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 9) {
    record.setFieldValue(f9_id, 1);
    record.setFieldValue(fx9_id, 0);
    } else

    if (reward == ‘YES’ && over_15 == 10) {
    record.setFieldValue(f10_id, 1);
    record.setFieldValue(fx10_id, 0);
    }
    }

    // Replace with your own code
    var msg = “Done!”;
    return msg + ‘ ‘ + over_15;

    }

    Test2();

    #36354
    Sam Moffatt
    Participant

    Let’s take a step back, my guess here is that you’re trying to port to TapForms a workflow that is based on maybe stamps or some other process today. Each purchase you get a stamp on a card and after 15 stamps, you get a voucher/coupon for a free item (or you simply hand in the completed card).

    If that’s the case then I’d model that with a “card” form that has 15 checkboxes on it and then those get ticked off. If you purchased 19, a new card record would need to be created with those four items ticked. You could have a customer field in here though I’d really suggest modelling that as a form because then you can lookup by customer and see their loyalty cards. You could in theory do some form scripts in the “customer” form which just accepted how many items were purchased and would encapsulate the logic of the cards.

    One item that would work here is in the “customer” form is setting up a JOIN field on a calculation field that found all of the “cards” that are completed and let them be redeemed. If there was a “redeemed” checkbox on the form that could be used as a part of a toggle to filter records.

    To recap:

    – “customer” form with all of the customers with 1:M to “card” form
    – “card” form with each of the purchases checkboxes and a “redeemed” checkbox
    – form script in “customer” to check the boxes and create new card records
    – JOIN field in in “customer” to find fully checked cards that aren’t redeemed

    This is one way of tackling the problem that I think is a little closer to what you might have started with but this is a bit of a stab in the dark.

    —-

    Let’s take a different approach that would be modelled more off a more integrated system. For data entry, it’s adding a record for each purchase that is made. Ideally that’d be automated with your POS or similar system. If you start with a customer form, then you pull up the customer record first and add their purchases to it defaulting to the current date. You could also model this as a quantity count which would be easier to enter but that makes it a little harder to do the next part.

    I’d also model it as another form setup with Link to Form 1:M for the purchases that are made. You could automate creating new “coupon” records that link to the purchases automatically and have a “redeemed” flag on the coupon. This is in a sense replicating the card aspect to have each of the purchases be a “stamp” in the record. Each has 15 items linked and that’s could be automated by a script.

    Similar to the above the cards could be linked together and you could use a JOIN field to have it show up.

    Do either of these sound like something closer to helping solve your problem?

    #36345
    Brendan
    Keymaster

    The alternative would be for you to use a Link to Form field or a Table field.

    Perhaps just a Table field would suffice for your case.

    This way you could add a Date field to your Table field and then add as many sub-records as you like. Maybe even add a separate Title or Description field to the Table field so you can describe what each Date represented.

    #36333
    Karl M. Rowe
    Participant

    Hi, Brenden!

    “I guess I’m confused by would be noted. Is that something that needs to be automated too? What do you mean by noted?”

    The person I am calling the “admin” would use pen and paper to make a “note” of the customers that have reached the 15-unit purchase threshold, entitled them to a free unit. The admin would also make a “note” of how many checkboxes in the second set have been checked (there is a “Calculation” field that indicates how many checkboxes have been checked so that after both sets of checkboxes have been reset, this number of checkboxes corresponded to the previously checked checkboxes in the second set of checkboxes would be checked in the first set of checkboxes. I would love to create a script that would be run on all records containing 15 or more checked checkboxes to reset both sets of checkboxes and then fill whatever number of checkboxes there were in the second set of checkboxes in the first set of checkboxes. But at present I have no idea how to designate which checkboxes should checked or unchecked, as the case may be, or how an FOR/NEXT loop can be employed in such a script to set within the first set of checkboxes the equivalent number of checkboxes that had been set in the second set of checkboxes.

    “Is it that when all 15 are checked, the first of the X checkboxes must be then clicked, then the next time all 15 are checked, then the 2nd of the X checkboxes must then be clicked?”

    No; my previous explanation here was confusingly awful, and I hope what I’ve said above clears up the ambiguity I caused you and others here trying to comprehend my explanation.

    “Maybe I’m just being daft. Sorry.’

    I’m sure you aren’t daft. I just wasn’t clear and I’m sorry.

    Peace

    #36328
    Karl M. Rowe
    Participant

    Hi, Sam!

    “Why not record the purchase events and calculate how many purchases from there?”

    This database is being built for non-computer literate people, who would only be responsible for nothing purchases made and by whom; nothing more.

    The “admin” would note the purchases made daily and note the free items that would be awarded to eligible customers, snd reset the two sets of checkboxes in the database as required. Now I was given some sample code to use in a script, but I’ve no idea how to identify each of the checkboxes using the app, but this database isn’t something I would build for my use.

    Pesce

    #36322
    Karl M. Rowe
    Participant

    “The four ‘Over-15’ checked checkboxes would be noted and the first four of the first set of checkboxes would then be checked. I would love to be able to automate these two functions with a script.”

    I’m sorry; the items that correspond to the first 15 checkboxes as well as four checkboxes in the “Over-15” checkboxes are the number of items purchased during a calendar month by the customer. I had tossed out 19 items as an example without explaining why 19. If the customer were to have purchased 19 items during the month, this would be recorded in the database by making sure that all 15 of the checkboxes in the first set are checked, and making sure that four of the ten “Over-15” checkboxes in the second set would be checked.

    A search of the database for all records containing a “Yes” at the end of a month would include this record, indicating that this customer is entitled to a free item, but the 15 checkboxes of this record and all other “Yes” records would then need to be reset (so I would definitely have a use for the script you provided to reset these checkboxes!). This means that for each “Yes” record, I would do such a reset and then use the number in the database that indicates the total number of “Over-15” checkboxes checked—in the case of this record that number is “4”—to set four of the 15 checkboxes just reset and then reset the “Over-15” checkboxes (using a similar script to reset all ten checkboxes).

    The database is ready to record subsequent purchases made, which would entitle this same customer to another free item should she purchase an additional 11 items during the following month. I realize this explanation was needlessly verbose, but I rushed this post. I’ll read it layer, but I hope you should get the drift.

    Peace

    #36321
    Brendan
    Keymaster

    Hi Karl,

    Thanks for the file. I’ve just had a chance to look at it with your formulas.

    However, I’m not sure what you mean by this:

    The four “Over-15” checked checkboxes would be noted and the first four of the first set of checkboxes would then be checked. I would love to be able to automate these two functions with a script.

    Here’s a script that’ll reset the checkmarks for the first 15:

    function Reset_Checkmarks_1_15() {
    
       var f1_id = 'fld-66cc9d4ad3c149c496cd3be90ea0f88c';
       var f2_id = 'fld-0dca226557ba47d2b806dd2f20d955ec';
       var f3_id = 'fld-e084b0d50e104044ab8baf2df11ae1e4';
       var f4_id = 'fld-6ee4490027334c8ea99f9e0365fef5f7';
       var f5_id = 'fld-b31757d2bda64dbfadf5fa3569857c33';
       var f6_id = 'fld-fbb171c0d7c14d90b5a248ea6baab1a9';
       var f7_id = 'fld-43a5c0ff16694eb19325b9c24dcaa2de';
       var f8_id = 'fld-4f1cbec2e2bd475b8a58badd20e66826';
       var f9_id = 'fld-9985de5176ac4861890a245c729e818a';
       var f10_id = 'fld-c5cf49dd9e954f18952e0eb7354f93aa';
       var f11_id = 'fld-49c502ea885342738df3ce1958d0542e';
       var f12_id = 'fld-22395b52e8a344e8b23499df65def764';
       var f13_id = 'fld-07b05a9ad759465abd4ffc436e74b11e';
       var f14_id = 'fld-6be47e6efbee473b9a725e67167dd90c';
       var f15_id = 'fld-d507eb4e113d4380b1ab5f2f20518e6c';
    
       record.setFieldValue(f1_id, 0);
       record.setFieldValue(f2_id, 0);
       record.setFieldValue(f3_id, 0);
       record.setFieldValue(f4_id, 0);
       record.setFieldValue(f5_id, 0);
       record.setFieldValue(f6_id, 0);
       record.setFieldValue(f7_id, 0);
       record.setFieldValue(f8_id, 0);
       record.setFieldValue(f9_id, 0);
       record.setFieldValue(f10_id, 0);
       record.setFieldValue(f11_id, 0);
       record.setFieldValue(f12_id, 0);
       record.setFieldValue(f13_id, 0);
       record.setFieldValue(f14_id, 0);
       record.setFieldValue(f15_id, 0);
    
       form.saveAllChanges();
    
    }
    
    Reset_Checkmarks_1_15();
    #36315
    Brendan
    Keymaster

    Hi Karl,

    When you export records, if you use the Tap Forms Archive format, Tap Forms will export the form template along with all the records. That’s a more complete way of sending someone your database.

    It’s also handy for copying a form and all its records from one document to another or to give to another user.

    So in this case, your template with any Calculation or Script fields did not come across.

    I’m working on some access controls code for the next update to Tap Forms which would allow you to specify for a specific form what a user of that form could do. E.g. edit form, add records, delete records, update records, etc. It’s not ready yet and so far it’s just on macOS, but I will bring it over to iOS once I’ve got the Mac version complete.

    #36310
    Karl M. Rowe
    Participant

    Hi, Brenden!

    Thanks for posting replies to my post. I’ve learned a little more about what this database is capable of doing.

    Attached to this post is a .CSV file (Loyalty15.csv), which is just a copy of my database, which contains three scratch records. In my original are two sets of checkboxes, the first set of 15 and the second set of 10. What you will see when it is imported are 15 text fields and 10 text fields, respectively. I don’t know if the “Checkbox” field type can be retained after the exporting and importing of the database, but I had to change the field type after importing it afresh into the app.

    I used your idea to make a Calculation field to sum the first set of checkboxes; if the first Calculation field equals 15, then the second Calculation field becomes “YES.” If not, the second Calculation field remains “NO.”

    I used an additional Calculation field to sum the second set of checkboxes; “Over-15” contains the total number of checked checkboxes.

    To explain, customers are rewarded with a free item for every 15 items purchased. If anyone purchases 19 items, for example, there will be a “Yes” and “4.” A search reveals the number or records in which all of the first set of checkboxes have been checked; these records are recorded elsewhere, and all 15 of these checkboxes would then be reset. The four “Over-15” checked checkboxes would be noted and the first four of the first set of checkboxes would then be checked. I would love to be able to automate these two functions with a script.

    There’s room for improvement and any suggestions that you and others here might have to improve this database would really be appreciated. I did wonder if it was possible to line up both sets of checkboxes horizontally, instead of as they are now, vertically; if this is possible, I would appreciate your pointing out to me a web page containing the steps required to do this.

    Lastly, I wondered if there was a way to secure the database, to make it impossible for users without a password (or permissions) to delete records; they could add records, run searches, but not delete any of them. How might I accomplish this using my iPad? Thanks.

    Peace

    #36309
    Karl M. Rowe
    Participant

    Hi, Sam!

    I appreciate your pointing out to me how I might use a script with my database to reset a set of checkboxes. I’d like to see a few examples of how such might be used. An example of an “Are you sure (y/n)?” prompt using Javascript is something I’d also be interested in seeing. Thanks for your reply.

    Peace

    #36289
    D J Leason
    Participant

    @ Sam Moffat
    # How to handle log entry?
    Immediate thought was to use a script to create a new child entry that copies the calculation field you have but part of me wonders if you’re thinking about this the wrong way in that this is already your daily log! Just add the records per day and you’ve got your log (duplicate if that makes sense).

    That log entry is for the weight to volume method only, which I don’t use daily. I can see the entry in the Form where created in the MCLV so that does give me a chronological list of tinctures made using the W2V method. I can see the entry in [Herb] Form / [WIP_W2VC Link to Form table], which gives me a list of each time I started that particular herbal tincture using that particular method but it does not show in the MCVL there because it’s just a [Link to Form] field and for the same reason, I can’t drag it into a new layout. So to get a chronologically ordered list for the year, although admittedly less expedient, I can physically copy and paste each entry to the [Daily Herb Log Form], (I haven’t advanced to Scripts or child entries quite yet), which helps me plan my calendar for next year. I could have a [Herb Log Entry] calculation for each Form with activities, copying and pasting each until I learn how to write scripts. Is that what you mean by duplicate? I really do appreciate all your help!

    #36288
    Sam Moffatt
    Participant

    TapForms doesn’t cascade deletes out of the box if I remember correctly. There’s some nuance in the Link to Form on if it “Deletes” or “Unlinks” for removing child records manually but if you delete a parent record, I don’t think it cascades those changes.

    You could use a form script to do a cascading delete function, most of the time I’m adding records and very rarely delete them so it’s not a problem personally I have.

Viewing 15 results - 2,416 through 2,430 (of 2,950 total)