Hello, I am trying to add one hour to the value from a date time field
and put it into a variable recdate
here is what I’ve tried but I keep getting an error
any help would be appreciated
Try2() {
var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var recdate = dateadd(mydate,0,0,0,0,1,0,0);
return recdate;
console.log(recdate);
}
Try2();
returns error
-05-022020, 1:01:26 PM / Daily copy / Try2
Try2: ReferenceError: Can’t find variable: dateadd, line:(null)
The above post needs clarification: the code only works on a text type field and not in a number type field. I would like to know how the script should be amended to work on a number type field
I am getting the following error:
02/05/2020, 18:24:01 / Time spent / add 0s to Time charged for (not empty)
add 0s to Time charged for (not empty): TypeError: value.replace is not a function. (In ‘value.replace(find_text, replace_with)’, ‘value.replace’ is undefined), line:(null)
when running the following script
var time_charged_for_id = 'fld-755fd264b59b42e59c7254edf03ea281';
function findAndReplace(find_text, replace_with) {
for (let rec of form.getRecords()){
let value = rec.getFieldValue(time_charged_for_id);
if (value) {
rec.setFieldValue(time_charged_for_id, value.replace(find_text, replace_with));
}
}
form.saveAllChanges();
return;
}
findAndReplace(/[a-zA-Z0-9]*/, '0');
I created a test database and it ran and did what is should. But in a working database it is causing the error. The field type is the same (a number field) in the test database and the working database.
The code was provided by Daniel Leu in the exchanges at https://www.tapforms.com/forums/topic/find-and-replace-script-to-replace-anything/.
Because I do not really have any understanding of JavaScript I cannot tell why it is not working.
I would grateful for any help in identifying what is wrong.
Most of the Javascript references that are basic Javascript should be relevant to Tap Forms. There are some functions that are not part of the Javascript ES6 standard that web browsers commonly implement that you might not see. Most of the time anything that references window, document and the DOM will not be relevant with Tap Forms. Unfortunately Javascript’s use in web browsers isn’t entirely standardised which leads to confusing documentation on the web.
In a form I have the following fields:
1. Invoice amount [the amount I invoice for a piece of work]
2. Amount paid [the amount a client pays]
3. Amount due [which is a calculation field – 1. – 2.]
4. iZettle charge [if the client pays by iZettle then iZettle charge]
5. Amount paid into bank account after iZettle charge [a calculation field – 3. – 4.]
6. Bank charge [if my bank makes a charge the bank charge]
7. Amount paid into bank account after bank charge [a calculation field – 3. – 6.]
8. Final amount received [which will be either 3., 5. or 7. 8. will then be use in various reports.]
I would like to know whether it is possible to use a calculation or rather if I should use a script
to achieve.
To put into 8.
1. if 5. and 7. are both zero than 3.
2. if 5. is not equal to zero then 3 – 5
3. if 7. is not equal to zero then 3 – 7
For either I would be grateful with how I can construct the appropriate calculation or script.
Daniel,
Apologies for my comments, they were not intended to disparage your helpful replies – more my frustration with trying to understand the pages you linked (mainly to do with JavasScript for websites) and its relevance to Tap Forms (and the sparse practical information currently available) for someone who does not understand it.
Anyway I have finally worked out where to put
findAndReplace(/[a-zA-Z0-9]/, ‘replace’)
That is right at the end of the code you provided and now provides what I need. Thank you for providing code.
To potentially work around this, you could use a script field instead and have the script field update the value of the other fields correctly. That way you only have one thing executing (your script field) and it’ll update the fields correctly. You’ll then have to convert the calc fields into normal number fields to finish everything up.
Hi Sam,
Nice script, but perhaps there has been a change in the syntax.
Looks like line 44 needs the change in two places ‘ID’ -> ‘Id’.
Thanks,
John
4/18/20, 11:58:17 AM / Movies not owned / SamsUnmodifiedScript
SamsUnmodifiedScript: TypeError: sourceFields[sourceId].getID is not a function. (In ‘sourceFields[sourceId].getID()’, ‘sourceFields[sourceId].getID’ is undefined), column:41, line:44
Thanks to both of you. I was already using “Saved Search” but display of number of these matches is a bit subtle for me, and I already have ten “Saved Search” categories displayed in my Multi-column list view. The more prominent record count for Forms more pleasing to my eye. If desired, Sam’s script can move the occasional record between forms for me without re-entering the data.
I appreciate the elegantly simple integration of Java scripting you have done, and have not used it until now.
As an aside, a solution I’ve posted elsewhere is to use a link to form field with a second form which will give you the table interaction style still and the ability to add in your own sort field. It does require some scripting, it isn’t entirely bulletproof but it does generally work.
Hi John,
Ya, as Sam suggested, a Saved Search is your best bet for handling this sort of task. It’s what I designed Tap Forms to do for you.
But if you must, you can look into Sam’s script or you can use the Export Records command to export a list of records, without the Export Record IDs option enabled, then use the Import Records command to import those records back in to your other form.
Thanks,
Brendan
Out of the box I think the suggestion is to just use a search to filter records that should be included or excluded. Tap Forms’ saved search feature is powerful and allows you to easily see a subset with navigation displayed on the left.
A while back I wrote a script to copy records between forms, though deleting I purposefully exclude because of the obvious risk of data loss though it should work fine.
Oops. Ok, I’ve just fixed the printing bug with Script fields not being printed.
Hi Alejandro,
Tap Forms can only create Saved Searches on the parent form. Not on the child forms.
But you can create a Saved Search on the child form directly to filter that. You just can’t filter the parent records directly with values obtained from the related child form.
However, you could write a script to get information from the child form to propagate up to the parent and then do searches on that. Or with a one-to-many relationship, you could add a Calculation field or a Script field which extracts information from the parent form. Then you could add the search directly to the child form.
Hope that makes sense.
Thanks,
Brendan
Thank you Daniel,
I will have a deep look at your script.
On the other hand, I expressed myself somewhat misleadingly … it sounds you think of the Apple Apps “Notes and Photos” I wrote about but with Notes and Photo I mean the field types “notes” and “photo” Tap Forms offer…