Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
February 19, 2023 at 10:05 AM #48953
In reply to: Restore a form?
Glen Forister
ParticipantThe record isn’t important enough to warrant work. But the next problem might be.
BUT, the fact that all those backups I have are useless unless I want to replace all my Forms and lose all the data in any or all 67 Forms since the last backup is appalling. Also, I guess I’ll never compact them again since I’ll never know when something might happen and I need that deleted information. I had compacted it because I had been doing some experimenting with Scripts and other features and after the session I was deleting records and Forms.
The only way to have a backup is to archive all 67 Forms individually? That is ridiculous.
Also, where is the option to engage a window “Are you sure you want to delete this record” with a yes or no/cancel option is almost unheard of in programs.
Disappointed… In the past with my other database program there were many times I had to resort to a backup file and replace the original with that file. That program backed up each “Form” into a separate file and was a real backup. Sure, it took longer to sync and backup, but it worked and your system doesn’t.
February 16, 2023 at 3:36 PM #48940In reply to: Repurpose previous record scipt
Daniel Leu
ParticipantAs I mentioned before, the return type of the script needs to be set to
number.-
This reply was modified 2 years, 8 months ago by
Daniel Leu.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksFebruary 16, 2023 at 3:08 PM #48939In reply to: Repurpose previous record scipt
Glen Forister
ParticipantI thought I was done. I was double checking that Script field ID, and wondered why it didn’t show up in the script editor and then forgot about that.
I hit refresh and now I have the totals incrementing, but instead of adding the previous total to the current number, it is concatenating them.
One of the things I love about programming is the surprises you don’t expect because of flawed logic…
0 0
50 500
100 100500
100 100100500
100 100100100500
20 20100100100500
60 6020100100100500February 16, 2023 at 2:59 PM #48938In reply to: Repurpose previous record scipt
Glen Forister
ParticipantI didn’t know it was there. I’ve been using the Script Editor to get those inserted.
Thanks.I appreciate the way you organized it. That is a lot easier to read.
I’m having trouble reading and understanding the objects, etc. and have to study a bit more to understand it. When done I’ll attempt another use for the code finding out how many days between the date of the last treatment of the previous entry and the date of the current entry and record that in a Days between treatments.
I have other work to get done first though. Even though I’m 79, I can’t get enough done with my insect collection and prepare for another season of collecting. Being retired is a lot of work.
February 16, 2023 at 2:42 PM #48936In reply to: Repurpose previous record scipt
Daniel Leu
ParticipantGreat that it works for you too!
Yeah, to make it easier I consolidated all the field IDs at the top. To get the
total_id, which is the ID of the script field, you need to close the script editor and look at the form editor. See attachment. You can get all the other IDs from the left side panel in the script editor.Attachments:
You must be logged in to view attached files.Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksFebruary 16, 2023 at 12:30 PM #48935In reply to: Repurpose previous record scipt
Glen Forister
ParticipantWhile working with it I noticed the IDs were wrong also as you pointed out. Don’t know how that happened.
I’ll have to compare this script with the previous one to see what you did, but with the changes you mentioned in the program and your last script, it worked.
Thanks for the work. Hopefully I can transfer this to other forms and make it work there also.
February 16, 2023 at 11:57 AM #48934In reply to: Repurpose previous record scipt
Daniel Leu
ParticipantYou need to select ‘script’ and not ‘calculation’ for the field type, return type is ‘number’.
The script had some errors too like incorrect field ids.
function Season_to_date() { var date_id = 'fld-e2d20da877cb4a6c8fd72153b86f1ab1'; var donation_id = 'fld-05c429d6a4484061b554aa584a45f8fc'; var total_id = 'fld-7c6b9bb288ab47e0b295af6eacc9cd26'; var records = form.getRecords(); var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousRecord = records[currentRecordIndex-1]; } else { return 0; } // Is this the beginning of the year? var date = record.getFieldValue(date_id); if (date.getMonth() == 0 && date.getDate() == 1){ return 0; } var today = record.getFieldValue(donation_id); var previous_total = previousRecord.getFieldValue(total_id); var total = today + previous_total; console.log("Today: " + today) console.log("Previous: " + previous_total) console.log("Total: " + total) return total; } Season_to_date();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksFebruary 16, 2023 at 10:34 AM #48932In reply to: Repurpose previous record scipt
Glen Forister
ParticipantI did have a record that had no data, date or values. Deleted that. Also made sure my added records for Jan 1 had the value = 0 for donations (that field was empty).
Now the script runs without errors with the original lines, or those lines replaced with the above correction for undefined.But, all my records have nothing in the Totals value. All blank.
I checked the script window and the value = number. Also the field Total is calculated and that value = decimal with zero decimal places.
Stopped the program, loaded it again and brought up the Form and refreshed it many times and no totals show up.
Is there a way to do this?
Thanks. Code below just so you know what I’m working with.function Season_to_date() { var records = form.getRecords(); var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousRecord = records[currentRecordIndex-1]; } else { return 0; } // Is this the beginning of the year? var date = record.getFieldValue('fld-0720a5baa6fc4980aee22798bd089714'); if (date != undefined && date.getMonth() == 0 && date.getDate() == 1){ } // if (date.getMonth() == 0 && date.getDate() == 1){ // return 0; //} var today = record.getFieldValue('fld-61c03b767f2c497491d10a28db8abdb3'); var previous_total = previousRecord.getFieldValue('fld-f6bc7e82da874579940fb8afc167dac4'); var total = today + previous_total; console.log("Today: " + today) console.log("Previous: " + previous_total) console.log("Total: " + total) return total; } Season_to_date();I just ran it again to verify and I get using one statement:
2/16/23, 9:26:49 AM / Donations / Yearly
Yearly: TypeError: undefined is not an object (evaluating ‘date.getMonth’), line:(null)The other statement gives me:
2/16/23, 9:29:25 AM / Donations / Yearly
Today: undefined
Previous: undefined
Total: NaNI’m really confused. Don’t know what is going on.
Here is my file.
I would like to see my donations for any single year that I can see with a search view.
I have a script in the Total Field and a similar one (maybe different now) in the Script designer field.Attachments:
You must be logged in to view attached files.February 15, 2023 at 8:34 PM #48930In reply to: Repurpose previous record scipt
Brendan
KeymasterScripts can’t be run line by line due to how Apple’s JavascriptCore framework works.
The best you can do is to put
console.log("got here")orconsole.log(someVariable)statements into your code.But when you see
undefined, it means exactly that. The value you’re trying to call a method on is empty or hasn’t been initialized with a value.So you should add
date != undefinedinto yourifstatement where you callgetMonth().if (date != undefined && date.getMonth() == 0 && date.getDate() == 1){ }You may have a record that has no date value, so that’s what would cause that error.
February 15, 2023 at 7:51 PM #48928In reply to: Repurpose previous record scipt
Glen Forister
ParticipantThe TF crashed. When it opened and I ran refresh again.
I get no errors:
2/15/23, 6:48:31 PM / Donations / YearlyBut, all my values in the Total col are blank.
Would help if the script could be run line by line. I assume it can, but haven’t found it.
-
This reply was modified 2 years, 8 months ago by
Glen Forister.
February 15, 2023 at 7:40 PM #48926In reply to: Repurpose previous record scipt
Brendan
KeymasterOh that’s weird. I didn’t know JavaScript had different scope rules than most every other programming language I know.
February 15, 2023 at 5:43 PM #48921In reply to: Repurpose previous record scipt
Glen Forister
ParticipantThat didn’t help. I get error in line 16 and playing with that I’m not sure where I’m at.
Added a backtick char.Here is the code I was using for my rain totals, but the rain season was from Oct 1 to Sept 31 of each year which required a loop I think to check for the end of the season. Since for this purpose, the year I’m grouping is for the tax year Jan 1 to Dec 31. So, didn’t think I needed the search for Oct 1 date. I thought if I took out that portion that this script would do the job of letting me see all years worth of donations and set up a view of only one specific year and see donations starting at 0 and adding up the amounts until Dec 31. Seemed simple.
This is the Rain script, so I assume I have to replace the id code like this (‘fld-0720a5baa6fc4980aee22798bd089714) with the id code for the field I want in my donation form.
So, do I have to start over or can I use this code with the correct changes. Sorry, thought this would be easy. Hopeful and thank you.
================function Season_to_date() { var records = form.getRecords(); var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousRecord = records[currentRecordIndex-1]; } else { return 0; } // Is this the beginning of the year? var date = record.getFieldValue('fld-0720a5baa6fc4980aee22798bd089714'); if (date.getMonth() == 9 && date.getDate() == 1){ return 0; } var today = record.getFieldValue('fld-61c03b767f2c497491d10a28db8abdb3'); var previous_total = previousRecord.getFieldValue('fld-f6bc7e82da874579940fb8afc167dac4'); var total = today + previous_total; console.log("Today: " + today) console.log("Previous: " + previous_total) console.log("Total: " + total) return total; } Season_to_date();-
This reply was modified 2 years, 8 months ago by
Glen Forister.
February 15, 2023 at 4:10 PM #48920Brendan
KeymasterThere’s no need for scripting just to get totals. You can just set the Calculation Summary option on all the fields you want to get a total for to appear at the bottom of the records list.
I haven’t had time to write the form for you Yvette. Sorry about that. But I would suggest starting with just creating the form as you have it now in the spreadsheet. Just add the fields one by one setting the field types appropriately. Then set the
Group Records Byoption toCategoryand the First Sort Field to whatever the next level of sorting it is that you want. Probably theNamefield.Then set the Calculation Summary setting for each of your Number fields. Or click the
∑symbol at the bottom of the Multi-Column List View to turn on the Calculation Summary Row. Now you can click the popup buttons to have Tap Forms generate totals for you.To see sub-totals for each category, just enable the
Show Group Summariesoption available from the little menu button that appears at the top-right of the multi-column list view.February 15, 2023 at 3:53 PM #48914Brendan
KeymasterHi Kurtois,
That’s the video channel for Sam Moffatt. You’ll find him fairly active on the forums here. Especially the Script Talk forum.
For the best tutorial videos, you can find links to them on my Support page (https://www.tapforms.com/support) or select Video Tutorials from the Help menu in Tap Forms 5 for Mac.
Or here for Mac:
https://vimeo.com/channels/tapformsmac5
And here for iOS:
February 15, 2023 at 3:32 PM #48912Topic: Repurpose previous record scipt
in forum Script TalkGlen Forister
ParticipantThanks for the script for rain totals. Now I figure I can make that do the same for donations. Am I on the right track? I keep getting syntax errors or other errors trying to get the syntax right. Am I way off track? Attached is my screen shot. I can’t seem to get the {} deletions right.
– I deleted the “beginning of the year” section.
– Replaced the variables “today” & “previous_total” ID values with the ones appropriate for my form. Now it looks like this.function Season_to_date() { var records = form.getRecords(); var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousRecord = records[currentRecordIndex-1]; } else { return 0; // xx = line deleted xx } xx // Is this the beginning of the year? xx var date = record.getFieldValue('fld-0720a5baa6fc4980aee22798bd089714'); xx if (date.getMonth() == 9 && date.getDate() == 1){ xx return 0; } var today = record.getFieldValue('xxxxx'); //replaced val with my value from form var previous_total = previousRecord.getFieldValue('fld-xxxxx'); //replaced val with my value from form var total = today + previous_total; console.log("Today: " + today) console.log("Previous: " + previous_total) console.log("Total: " + total) return total; } Season_to_date();-
This topic was modified 2 years, 8 months ago by
Brendan. Reason: Added back ticks around code -- Brendan
Attachments:
You must be logged in to view attached files. -
This reply was modified 2 years, 8 months ago by
-
AuthorSearch Results