Search Results for 'form.getRecords'
Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Search › Search Results for 'form.getRecords'
-
AuthorSearch Results
-
February 20, 2023 at 7:12 PM #48971
In reply to: days between dates
Glen ForisterParticipantOk, Tried that.
End result = Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
Days_Between_Dates()
2/20/23, 6:24:40 PM / Psoriasis / Days since last Trt.
Days_Between_Dates()
Days since last Trt.: ReferenceError: Can’t find variable: previousRecord, line:(null)I’ve done lots of Basic, some Pascal, and some R in the past, but this is very different and I’m lost. Went through the basic training, but still new. It will take lots of experimenting and work to get to where I need to be to fix this. In time I will I hope, but still in the process of making TF usable to me before I branch off into another programming language.
PS, Have no idea what the “called…” after in the Console.log statement does. I just get a syntax error.
function Days_Between_Dates(){
console.log(“Days_Between_Dates()”);
var date_id = (‘fld-119ad5683104451ca6855e777a23ad21’);var records = form.getRecords(); // calls function getRecords()
var currentRecordIndex = records.indexOf(record);if (currentRecordIndex > 0) {
var previousday = records[currentRecordIndex-1];
} else {
return 0;
}var today = record.getFieldValue(date_id);
var previous_day = previousRecord.getFieldValue(date_id);
var total = today – previousday;console.log(“today: “)
console.log(“previousday: “)
console.log(“total: “)return total;
}
Days_Between_Dates()Thanks for looking, but…
- This reply was modified 1 year, 10 months ago by Glen Forister.
February 20, 2023 at 11:42 AM #48962In reply to: days between dates
Glen ForisterParticipantI added that. It just prints to the screen after every recored looked at I guess. I don’t get it.
There aree 26 records.Here is the result.
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
Days_Between_Dates() called …
2/20/23, 10:38:59 AM / Psoriasis / Days since last Trt.
Days_Between_Dates() called …
————-function Days_Between_Dates(){ var date_id = ('fld-119ad5683104451ca6855e777a23ad21'); var records = form.getRecords(); // calls function getRecords() var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousday = records[currentRecordIndex-1]; } else { return 0; } var today = record.getFieldValue(date_id); var previous_day = previousRecord.getFieldValue(date_id); var total = today - previousday; console.log("today: ") console.log("previousday: ") console.log("total: ") return total; } function Days_Between_Dates(){ console.log("Days_Between_Dates() called ..."); } Days_Between_Dates();
- This reply was modified 1 year, 10 months ago by Glen Forister.
- This reply was modified 1 year, 10 months ago by Brendan.
February 19, 2023 at 10:20 AM #48954In reply to: days between dates
Glen ForisterParticipantOk, missed that.
But I got all the syntax cleared and this script does nothing, not even printing to console the variable values. So I’ve proved I haven’t learned anything yet.
Any ideas?
Thanks.function Days_Between_Dates(){ var date_id = ('fld-119ad5683104451ca6855e777a23ad21'); var records = form.getRecords(); // calls function getRecords() var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousday = records[currentRecordIndex-1]; } else { return 0; } var today = record.getFieldValue(date_id); var previous_day = previousRecord.getFieldValue(date_id); var total = today - previousday; console.log("today: ") console.log("previousday: ") console.log("total: ") return total; }
- This reply was modified 1 year, 10 months ago by Glen Forister.
February 18, 2023 at 12:20 PM #48948Topic: days between dates
in forum Script TalkGlen ForisterParticipantI did some study and tried to determine the #days between the date of one record and the previous record. I can’t get past line one syntax. Help please?
Function Days_Between_Dates(){ var date_id = 'fld-119ad5683104451ca6855e777a23ad21'); var records = form.getRecords(); // calls function getRecords() var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousday = records[currentRecordIndex-1]; } else { return 0; } var today = record.getFieldValue(date_id); var previous_day = previousRecord.getFieldValue(date_id); var total = today - previousday; return total; }
February 16, 2023 at 11:57 AM #48934In reply to: Repurpose previous record scipt
Daniel LeuParticipantYou 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();
February 16, 2023 at 10:34 AM #48932In reply to: Repurpose previous record scipt
Glen ForisterParticipantI 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 6:26 PM #48925In reply to: Repurpose previous record scipt
Daniel LeuParticipantYou still need to reset the year-to-date field at the beginning of the year.
if (date.getMonth() == 9 && date.getDate() == 1){ return 0; }
Needs to be
if (date.getMonth() == 0 && date.getDate() == 1){ return 0; }
The function should look 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; } // Is this the beginning of the year? var date = record.getFieldValue('fld-0720a5baa6fc4980aee22798bd089714'); 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();
And again, this only works if there is a record for January 1st.
February 15, 2023 at 5:43 PM #48921In reply to: Repurpose previous record scipt
Glen ForisterParticipantThat 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 1 year, 10 months ago by Glen Forister.
February 15, 2023 at 3:32 PM #48912Topic: Repurpose previous record scipt
in forum Script TalkGlen ForisterParticipantThanks 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 1 year, 10 months ago by Brendan. Reason: Added back ticks around code -- Brendan
Attachments:
You must be logged in to view attached files.February 5, 2023 at 5:40 PM #48845In reply to: Result from one field in another field – same form
Daniel LeuParticipantOne cool feature in TF is that picklist entries can come from a form. So I have a form called ‘Brands’ that contains name and URL fields. I select this form to be the source of my picklist. Then in my main form, I use that picklist to select the brand. Further, I use a field script ‘URL Script’ to set the value of the URL field. The field script is triggered whenever a different brand is selected and then the URL field is updated accordingly.
When the script is triggered, it fetches all entries of the ‘Brands’ form and loops through them. Once a match is found, the URL field is set according to that matching record entry and the script aborted:
function Url_Script() { var brand_id = 'fld-feb500eed99747169d8d90db3a620243'; var url_id = 'fld-0a342472ca0b44b1a52c3758c5be92e4'; const brands_name_id = 'fld-8d373c0912154c69a7f579e696cd598c'; const brands_url_id = 'fld-0a342472ca0b44b1a52c3758c5be92e4'; let brand = record.getFieldValue(brand_id); // get the brands form. Note that the name of the form must match! let brandsForm = document.getFormNamed("Brands"); for (let rec of brandsForm.getRecords()){ if (rec.getFieldValue(brands_name_id) == brand){ let url = rec.getFieldValue(brands_url_id); console.log("found match: " + brand) + " with url " + url); record.setFieldValue(url_id, url); document.saveAllChanges(); return url; break; } } } Url_Script();
Hope this is what you were looking for. I have attached my example document.
Attachments:
You must be logged in to view attached files.January 18, 2023 at 10:46 PM #48715In reply to: List with Check box
BrendanKeymasterThe
Advanced Find & Replace
function is under the Records menu on the Mac version.There’s a script snippet called
Basic Loop
which just sets up a loop. But you would have to fetch the records first withvar records = form.getRecords();
and then get each record within the loop and then set the value of the field using therecord.setFieldValue(some_checkmark_field_id, 0);
function. The 0 would set the checkmark field value back to off.Don’t forget to do a
form.saveAllChanges();
outside of the loop at the end before the program ends so Tap Forms can save the values.This Form Script will reset all the checkmark fields for your
Shield
field back to OFF:function Reset_Shields() { var shield_id = 'fld-d13c2bafe6e8482288c551bd8c931373'; var records = form.getRecords(); for (var index = 0, count = records.length; index < count; index++){ var theRec = records[index]; theRec.setFieldValue(shield_id, 0); } form.saveAllChanges(); } Reset_Shields();
January 16, 2023 at 3:55 PM #48679In reply to: Learning JavaScript
Daniel LeuParticipantfunction 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();
January 16, 2023 at 2:25 PM #48675In reply to: Learning JavaScript
Glen ForisterParticipantThat is great. I put it in the script right after the other “var”s near the top. Hope that is the right place.
function Get_Previous_Record() {
var records = form.getRecords();
var currentRecordIndex = records.indexOf(record);
// added var for Oct 1st.
var previousRecord = nil;
var date = record.getFieldValue(‘fld-0720a5baa6fc4980aee22798bd089714’);
if (date.getMonth() == 9 && date.getDate() == 1){ // check for October 1st
return 0;
}
// end added var for Oct 1if (currentRecordIndex > 0) {
previousRecord = records[currentRecordIndex – 1];
}if (previousRecords != nil) {
// fetch some value and do some calculation with it and the current record
// the currently selected record is always accessed with the built-in variable
//record
}
}Get_Previous_Record();
January 15, 2023 at 10:52 PM #48670In reply to: Learning JavaScript
Daniel LeuParticipantThis should to the trick to reset the season total at the beginning of the year:
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() == 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();
January 14, 2023 at 2:38 PM #48648In reply to: Learning JavaScript
Daniel LeuParticipantHi Glen,
Thank you for sharing your form! The script Brendan posted is for a field of the type
Script
and notCalculation
.Here is the updated script that works for me:
function Season_to_date() { var records = form.getRecords(); var currentRecordIndex = records.indexOf(record); if (currentRecordIndex > 0) { var previousRecord = records[currentRecordIndex-1]; } else { 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();
-
AuthorSearch Results