Hi Glen, in your original script, you were reading the previous total from the wrong field. Now it should work as expected:
function toHrsMin(sec){
let str = "";
let h = Math.floor(sec / 3600);
let m = (sec / 60) % 60;
return h + ' hr, ' + m + ' mins';
}
function Accum_Tot() {
var records = form.getRecords();
var currentRecordIndex = records.indexOf(record);
if (currentRecordIndex > 0) {
var previousRecord = records[currentRecordIndex-1];
var previous_total = previousRecord.getFieldValue('fld-b2f9616bf5e44fb4880ad9addd2afc6e');
} else {
var previous_total = 0;
}
var today = record.getFieldValue('fld-44acc9d2314f41beb3f2257ace5bae01');
var total = today + parseInt(previous_total);
console.log("Today: " + toHrsMin(today))
console.log("Previous: " + toHrsMin(previous_total))
console.log("Total: " + toHrsMin(total))
return total;
}
Accum_Tot();
-
This reply was modified 2 years, 2 months ago by
Daniel Leu.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Dear members,
how can I prevent that my form field script runs three times? I need 3 event listeners for my form. But this code should only run once.
var letzter_eintrag = record.getFieldValue(‘fld-827f7254f04c462f887323172ef309ca’);
var brief_erstellt = record.getFieldValue(‘fld-8295048b2bee4f959bb952914117c266’);
var brief_versandt = record.getFieldValue(‘fld-c1e5d2c7de1844d2ae50fdcbe118232d’);
function ….{
call another function;
}
……
That is why I would prefer to use the script solution. Unfortunately, what Daniel supplied:
But, it adds the first two records then subtracts any following numbers which isn’t helpful.
I’ve looked at the script, but don’t understand how it jumps out of the loop and starts subtracting instead of adding to the total.
Can you please give me a script that works?
I tried to use the script from my rain totals script to do a similar job, but I’m missing something to be abel to add up the record totals, to an accumulation of the record totals.
Hope this is a simple fix. See attached archive file with dummy data – just getting started.
Attachments:
You must be
logged in to view attached files.
Do you mean from a Script? You posted in the Script Talk forum, so I’m not sure if you’re asking a general question or a script specific question.
You can use the Export Records function to generate a CSV file of your records.
Hi John,
There’s no function to trigger a script by double-clicking on a field.
However, you can have Tap Forms add 1 to another field if the Number field is manually changed by using a script.
When you call the record.getFieldValue(field_id) function, the field that corresponds to field_id will be monitored for changes. When the value changes in that field, the script will be executed and you can have it increment the value in another field, or return the value right from the script field which could be the monitored field’s last value plus one.
Thanks,
Brendan
Hi guys,
I would like to make a script that will add 1 (one) to an existing sum in a number field.
so that by double-clicking the field, it goes from, for instance, 110 to 111
But how can I do this?
kr.
John
Thank you for the quick reply, that’s perfect! I was hoping there was an easier way than writing script.
I appreciate the help!
Kathy
Hi Kathy,
One possibility for you instead of having all the fields from the link to form appearing there, click the little tool button that looks kind of like an X at the top-right of the table view. From there you can select and de-select the fields you want to see. Plus you can also drag the fields up and down and that will change the order they display on the horizontal table view for the Link to Form field.
Give that a try and see how it works for you.
If you need something other than that, you’ll need to write a script that pulls out the data from the child form to display it on the parent form.
Thanks,
Brendan
You could write a Script you could run that takes the shopping list values and adds them to the Reminders.
function Add_And_Update_Reminder() {
// Create new Date instance
var due_date = new Date();
// Add a day
due_date.setDate(due_date.getDate() + 1);
var event_info = {"list_name" : "Work",
"title" : "Test Event",
"priority" : 1,
"notes" : "test note",
"repeat_option" : 2};
var identifier = Utils.addToReminders(event_info, due_date);
console.log(identifier);
event_info["title"] = "Hello Reminder 2";
Utils.updateReminder(identifier, event_info, due_date);
}
Add_And_Update_Reminder();
-
This reply was modified 2 years, 3 months ago by
Brendan.
Hi,
If you setup your Recipes form with a relationship to an Ingredients form, then you could select some recipes to print to make a PDF file that you could browse while you’re shopping. Not exactly an interactive experience though like you might get from a dedicated shopping / recipes app. But it would be possible.
Another way might be to write a Form script that lets you select specific recipes and then inserts the ingredients for those recipes into another form that contains your shopping list items. This would be an involved script to write though.
At last this is the script that works:
function modifyFieldsBasedOnCondition() {
var fieldId1 = ‘fld-28b97ce8ab4f4f57a83aefa7e91f17fe’;
var fieldId2 = ‘fld-c2fd26ae62c1445692b3a0abc1e89158’;
for (var record of form.getRecords()) {
var valueField1 = record.getFieldValue(fieldId1);
var valueField2 = record.getFieldValue(fieldId2);
if (valueField1 === 4 && (valueField2 === null || valueField2 === “”)) {
record.setFieldValue(fieldId2, “Buen disco.”);
console.log(“Campo fieldid2 actualizado en el registro con campo fieldid1 igual a 4 y fieldid2 vacío.”);
}
}
form.saveAllChanges();
}
modifyFieldsBasedOnCondition();
Thank you Brendan and Daniel for your valuable help.
Bye.
Hi Brendan, thank you for your answer. The script is steel not working.
Attachments:
You must be
logged in to view attached files.
Hi. I want to do an script for autocomplete a note field called “Comentario” with “Buen disco.”, when the valoration field “Valoración” has four stars and, at once, the field “Comentario” is empty. I have not errors in the console, but the script does not work. Any help will be welcome. Thank you.
Attachments:
You must be
logged in to view attached files.
I just did:
Copy New Form to another experimenting Form.
Then imported the data file into it and ended up with just 3 records which were only the added record and the 2 changed records.
Where are all the other records. And, the calculations (not JavaScript) don’t work, but the names of the fields in the calculations are right. Do they have to be redefined?
This is ridiculously problematic. I never had any trouble like this in HanDBase when wanting to do this.