Something like this:
const fieldWebSite = 'fld-...'
const fieldWebSiteClean = 'fld-...'
var web_site = record.getFieldValue(fieldWebSite);
var new_web_site = web_site.split('?')[0];
record.setFieldValue(fieldWebSiteClean, new_web_site);
Re Times Used:
I’m not certain that this works, but I think to remember that the field trigger code parses the script for fld-... patterns. So when using const fieldTimesUsed = form.getFieldNamed('Times Used').getId(), you might avoid the trigger. Certainly @Brendan will chime in on this.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Yeah, the script is triggered again if you update it with your script. In situations like this, I use two fields, one with the raw data and one with the processed data.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thank you and I understood that is the current mechanic, but for me, the script fires twice because I suppose I’m changing the field that I’m watching. While this looping doesn’t cause an issue with this example, I have some other situations where the script firing twice is problematic.
Example attached.
import
open console
copy into website field a URL with query string, i.e https://example.com/movies?si=zyH0Aqaaa
console shows
Script Excecuted 6/8/2022, 7:32:50 PM for https://example.com/movies
Script Excecuted 6/8/2022, 7:32:50 PM for https://example.com/movies
Attachments:
You must be
logged in to view attached files.
Right now you would need separate photo fields to be able to print an entire sheet with different photos on it.
As for referencing photo fields from a Calculation field, that’s not possible. But you can access the list of photos from a Script. But not the actual photos themselves. Just the metadata around the photos. Useful for building saved searches that might want to show only the records that are missing a photo.
As Daniel said, and you can also hide the Script Field from displaying on the form. It will still activate when the field is changed in the UI.
Create a field with the type script and put it there. It will only be executed when the field web_site changes. At the end of the script, add a form.saveAllChanges().
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
How do I implement field data scripting wihout looping? I understand field scripts and fields are watched via adding the field id. But how do I watch a field, change its value, and not cause a loop? I’m used to event driven functions where I could choose pre or post save, etc.
Example:
URL Field; If someone enters a URL with a query string, I want to strip out everything after the question mark. Where do i put this script?
var web_site = record.getFieldValue('fld-xyz');
var new_web_site = web_site.split('?')[0];
record.setFieldValue('fld-xyz', new_web_site);
I use several scripts as infrastructure/include scripts. They only contain function or constant definitions. Then I use runScriptNamed() to include these functions. Later, whenever I need, I can call one of these defined functions from these include files.
So for your example, define
function formScript(abc) {
console.log(abc)
}
Then from your calling script, you do
runScriptNamed("myIncludeScript")
and then later
formScript("hello")
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
you mean the Form Script will have access to a variable declared in a Field Script function ??? are all your vars global? this sounds strange to me.
What I understand is this:
function FieldScript() {
var xyz = ‘123’
form.rundScriptedNamed(‘formScript’);
}
Then in the Form Script:
function formScript() {
var abc;
//I can set abc = xyz
abc = xyz;
// and now abc will have ‘123’ in it ?
}
This doesn’t make any sence to me thinking about rules of encapusalation. Unless there is some type of ‘Global’ tag I need to use on the variable.
Please help
Thanks
If you setup a variable and populate it before you call runScriptNamed() then you should have access to that variable from within the script you’re running. So no parameter required.
I want to have a Form Level Script (DoSomething) that accepts an input parm ex DoSomething(‘abc’).
I’d like to call this script from various field level scripts using runScriptNamed(‘DoSomething’) but I do not see how to pass the value of ‘abc’ into the script on the runScriptNamed call.
Is it possible?
Thanks
Bernie
When a date field is changed with the date picker, the field script referencing that date field gets fired twice.
Simple repro case, just a date field (date_last_used) and field script
var date_last_used = record.getFieldValue('fld-xxx');
console.log("Process Excecuted "+ new Date().toLocaleString())
change the date manually and script fires just once.
use the date picker, and script fires twice.
Any suggestions for workarounds?
Attachments:
You must be
logged in to view attached files.
I’ve had a go at some Javascript but can’t get it to work. Basically I want it to take a search term off the clipboard, do a search and get the record ID for the found item and then copy that to the clipboard. It isn’t working so could someone tell me what I have done wrong?
var myForm = document.getFormNamed(‘Scopus RE’);
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var selected;
function search_records( haystack , needle ) {
var name_id = ‘fld-90984efc3585456ab56763adff0a5228’;
var rec;
for (const rec of haystack) {
if ( rec.getFieldValue( name_id ).toLowerCase().includes( needle.toLowerCase() ) ) {
results.push( { name: rec.getFieldValue( name )
} );
result_count++;
}
}
if( result_count == 0 ){
console.log( ‘No results found!’ );
}else if( result_count > 1 ){
multiple_results();
}else{
copy_record.getId( results[0] );
}
}
I don’t know JavaScript. I was wondering if there was a way on iOS to search a given form for a record (search either a given field or all fields – doesn’t matter) and then have tap forms open in that record? I was wondering if this is possibly via url scheme directly or if not by creating a script and then executing the script via url scheme. If the latter can someone help me with the JavaScript?
Looks like the context the script runs is different. Something Brendan will be able to answer.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks