Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
January 15, 2020 at 5:52 AM #39252
Topic: Time-Format yyyy-mm-dd
in forum Script TalkEddy
ParticipantHi Brendan!
Happy new year!
I’m not sure, if this is a bug of it I’m stupid…> I have a date field.
> I want to use the date in a script.
> Finally I need the date in YYYY-MM-DD FormatFor this I like to use the ISO-Format.
.”getFieldValue” returns:
Sun Apr 19 2020 00:00:00 GMT+0200 (CEST)If I now use “.toISOString” I get:
2020-04-18T22:00:00.000ZAs you see, the date is changing to one day before, because the time zone is ignored.
As a workaround I use
“date.toLocaleDateString(‘ja-JP’, {year: ‘numeric’,month: ‘2-digit’,day: ‘2-digit’}).replace(/\//g, ‘-‘)”But this seems not to be the most elegant way. Any other ideas?
Regards, Eddy
January 14, 2020 at 2:25 AM #39230Brendan
KeymasterI looked into the DataMatrix format a little closer and although Apple has a definition for it in their CoreImage Filters, it is not yet supported. I tried implementing the code in a similar way that I implemented the QR Code generator, but I got this error:
inputBarcodeDescriptor of type CIDataMatrixCodeDescriptor is not yet supportedSo I won’t be able to add it. At least not without investing in some other barcode generator library that might support it.
January 9, 2020 at 1:25 PM #39134Brendan
KeymasterHi Eddy,
It’s not possible right now because all of the code to fetch the location coordinates for a given address exists only on the screen that shows you the map. There’s also a delay in fetching the geo coordinates because another process has to be kicked off to call to Apple’s servers and wait for a response. It would require a new script API to support triggering the calls to Apple’s Core Location framework. I’ll add your request to my requests list.
Thanks,
Brendan
January 9, 2020 at 6:20 AM #39127Eddy
ParticipantHi there!
So, I wrote a little script to fill the location field with the information already stored in other fields. It works finde, BUT: After the location field is automatically filled now with the text, I have to clic manually on the loacation field to force to search and store the geo-coordinates.
QUESTION: Any way to let the location field be automatically completed with the geo-coordinates? As far as it works half-automatically (I just have to make a stupid click) I am full of hope…
Regards,
Eddy
function fill_locationfield() {
var street = record.getFieldValue(‘xxx’);
var postcode = record.getFieldValue(‘xxx’);
var city = record.getFieldValue(‘xxx’);
var country = record.getFieldValue(‘xxx’);var lacation_field_id = ‘xxx’;
var text_for_locationfield =
street + “, ” + postcode + ” ” + city + “, ” + country;record.setFieldValue(lacation_field_id, text_for_locationfield);
document.saveAllChanges();
}fill_locationfield() ;
January 4, 2020 at 7:40 PM #39090Topic: How to copy file attachments and images between records?
in forum Script TalkSam Moffatt
ParticipantI’m working on a merge record script to be able to take two records and merge them together. This isn’t too bad for almost all of the field types except for the photo and file attachment types. How do I copy the attachments from one record to another for the file and photo fields?
January 4, 2020 at 11:48 AM #39087In reply to: Calling a field value from a record or another form
Sonya Walters
ParticipantHi, its Sonya again,
It worked! Because I only ever have one record in the PortfolioPaintings link to form field, I tried the non-Child Loop method:
//-----------Pulls field from one-record linked form----------- function FramePriceFromPortfolioDB() { //Get id of record from current form var portfoliopaintings = record.getFieldValue('fld-0b51acdae23a47789d7210379a6ddf2f'); //Using the id, pull the one record in the linked form and find a field in that form // (since there is only one record in the linked form, the index value of zero works). var frameprice = portfoliopaintings[0].getFieldValue('fld-c9071aa3421e4715a6bda880b63a32a3'); return frameprice; } FramePriceFromPortfolioDB(); //. --- [ end script to pull linked form field]I went on to the Child Loop method but I’m getting an error with the “length” variable…
ScriptWithChildLoop: TypeError: undefined is not an object (evaluating 'portfoliopaintings.length'), column:48, line:12Here’s the script, sorry for all the code:
//---- Child Loop method ----- //Pulls the framecost field from linked portfoliopaintings form function recordsLoop() { var portfoliopaintings_id = record.getFieldValue('fld-fdfa6263cd8c49ceb0bb048a841ab469'); var framecost_id = 'fld-c9071aa3421e4715a6bda880b63a32a3'; var portfoliopaintings = record.getFieldValue(portfoliopaintings_id); for (var index = 0, count = portfoliopaintings.length; index < count; index++){ var framecost = portfoliopaintings[index].getFieldValue(framecost_id); if (framecost) { return framecost; } } return; } recordsLoop(); ---- [end code with Child Loop method] -----I think I’m all set since the first method works.
This is a fantastic database and software, thank you for your support.Sonya
January 3, 2020 at 5:02 PM #39080In reply to: Calling a field value from a record or another form
Sonya Walters
ParticipantHi, this is Sonya again, thank you for your suggestions on how to better document my questions.
Here is my entire script (partially written by clicking on fields):
function FramePriceFromPortfolioDB() { //Get id of same work in portfoliopaintings using the link var portfoliopaintings = record.getFieldValue('fld-0b51acdae23a47789d7210379a6ddf2f'); //Find the Frame price of that record in portfolio paintings var framecost = portfoliopaintings[index].getFieldValue('fld-c9071aa3421e4715a6bda880b63a32a3'); return "framecost"; // return "3.00"; this was a test }The string fld-0b51acdae23a47789d7210379a6ddf2f (mmmm in previous post) is the Field ID of the Link to Form Field (used in the join).
For index, I have tried inserting 16 (because the field I am looking to transfer is the sixteenth in the joined form Portfoliopaintings), as well as 2, and for kicks, 0.
But I am not sure how to fill the index string. In case it helps I attached a screen shot of the fields in my form, including the linked form. It doesn’t show all the fields in the linked form, in the screenshot, but the one I want is number sixteen, a numeric value.
I hope this makes sense, and.
Thank you for your help!
Attachments:
You must be logged in to view attached files.January 3, 2020 at 1:24 PM #39079In reply to: Calling a field value from a record or another form
Brendan
KeymasterHi Sonya,
I hope you don’t mind, but I put in a couple of tilde characters in your post to make your code more easily readable.
is
fld-mmmmthe Field ID for your Link to Form field?And what is the value of
indexwhen you use it?Can you please post the entirety of your script so we can have a better look at it?
Thanks,
Brendan
January 3, 2020 at 1:18 PM #39077In reply to: Changing Record Focus & Sorting
Brendan
KeymasterYou can setup different sort orders using Saved Searches for the same form, even if your Saved Search has no Search Rules defined. Then you can ask a form for a specific search if you like:
var search1 = form.getSearchNamed("Alpha Sort");var search2 = form.getSearchNamed("Number Sort");and so on.
But the sorts have to be defined outside of your script. When you create a Saved Search and specify the sort order, the database engine I use (Couchbase Lite) creates an index table that contains references to the records sorted by the order you’ve specified. So this is why the Saved Searches need to be created beforehand.
January 3, 2020 at 11:04 AM #39074In reply to: Changing Record Focus & Sorting
Larry Stoter
ParticipantHi Brendan,
Thanks – very helpful.
With regard to sorting, I would like to change the records sort order within the script. Or, more specifically, I would like to have a conditional branch within the script which returns different sort orders depending on the result of the conditional test.
I was thinking I could do this with form.getRecords() and then sort the array but there doesn’t seem to be an API function to write the sorted array back to the database. Instead, it looks as though this would need to be done with record.setFieldValues() for every record in the database …?
I guess part of the problem I have is that I see records and fields as more fundamental than forms and that forms are just a way to enter and display fields values for each record? So, I’m used to setting up forms/layouts as the final step in putting a database together, after I’ve got everything else working.
Perhaps the TapForms way to handle this is to set up several different forms, each with a different sort order and then use the scripts to move between forms ?
Happy New Year,
Larry
January 3, 2020 at 8:20 AM #39072In reply to: Calling a field value from a record or another form
Sonya Walters
ParticipantHi,
I’m a very inexperienced programmer trying to use the scripts function to draw data from one form to another from via a linked field.
I would like to transfer the price of framing a work from one form (portfolio paintings) to another (Serendipity) so as to not have to enter the same data twice.
I searched the forums andfound the information in this thread to be relevant and useful.
However I have almost no experience in using programming languages so the line of code
referenced in the thread aboveotherform[0].getFieldValue(‘fld-otherid’)
does not have enough information for me to implement it. The field I would like to pull in, is field number sixteen (starting from zero) in the linked form.
I find using “0” as the index does not return an error but “2”, “indexOf” and “16” all produce something like:
Script: TypeError: undefined is not an object (evaluating ‘portfoliopaintings[2].getFieldValue’), column:39, line:9
from the lines below:
var framecost = portfoliopaintings[index].getFieldValue(‘fld-nnn’);
// ^^
// error appears at this spotfunction FramePriceFromPortfolioDB() {
//Get id of same work in matching linked portfoliopaintings form:
var portfoliopaintings = record.getFieldValue(‘fld-mmmm’);//Find the Frame price of that record in portfoliopaintings
var framecost = portfoliopaintings[index].getFieldValue(‘fld-nnn’);
// ^^
// error appears at this spotreturn “framecost”;
}
FramePriceFromPortfolioDB();
Does anyone understand this question enough to tell me how to refer to the field in the linked record, and return its value?
Thank you for any help, and, happy new year!
SonyaJanuary 3, 2020 at 8:18 AM #39071In reply to: Calling a field value from a record or another form
Sonya Walters
ParticipantHi,
I’m a very inexperienced programmer trying to use the scripts function to draw data from one form to another from via a linked field.
I would like to transfer the price of framing a work from one form (portfolio paintings) to another (Serendipity) so as to not have to enter the same data twice.
I searched the forums andfound the information in this thread to be relevant and useful.
However I have almost no experience in using programming languages so the line of code
referenced in the thread aboveotherform[0].getFieldValue('fld-otherid')does not have enough information for me to implement it. The field I would like to pull in, is field number sixteen (starting from zero) in the linked form.
I find using “0” as the index does not return an error but “2”, “indexOf” and “16” all produce something like:
Script: TypeError: undefined is not an object (evaluating ‘portfoliopaintings[2].getFieldValue’), column:39, line:9
from the lines below:
var framecost = portfoliopaintings[index].getFieldValue(‘fld-nnn’);
// ^^
// error appears at this spotfunction FramePriceFromPortfolioDB() { //Get id of same work in matching linked portfoliopaintings form: var portfoliopaintings = record.getFieldValue('fld-mmmm'); //Find the Frame price of that record in portfoliopaintings var framecost = portfoliopaintings[index].getFieldValue('fld-nnn'); // ^^ // error appears at this spot return "framecost"; } FramePriceFromPortfolioDB();Does anyone understand this question enough to tell me how to refer to the field in the linked record, and return its value?
Thank you for any help, and, happy new year!
SonyaJanuary 2, 2020 at 6:15 AM #39064In reply to: Issues with very basic Field Script Output
Wayne Powell
ParticipantBrilliant, thank you Sam! I totally forgot the IT Crowd Mantra = “Have you tried turning it off and on again?”
Closing Tap Forms and restarting it fixed the issue, the script works again! Now I just have to fix my calculation values.
January 1, 2020 at 3:55 PM #39056In reply to: Changing Record Focus & Sorting
Brendan
KeymasterHi Larry,
You can’t directly access the Go To functions in Tap Forms from the Scripting engine.
But you can tell Tap Forms to select a record. However, it’s generally only used once in a script.
But instead of having the UI select different records, you can just get the records directly from your script.
Sorting is controlled by the Forms and Saved Searches. So whatever sort order you’ve specified on your Form or Saved Search is what will be used within the Script engine.
If you want to find out what your previous record is, you need to first get the list of records. Then you’ll need to pick out which record you want.
For example:
function Previous_Record() { var records; var previousRecord = record; try { if (search != undefined) { records = search.getRecords(); } else { records = form.getRecords(); } var indexOfCurrent = records.indexOf(record); if (indexOfCurrent > 0) { previousRecord = records[indexOfCurrent - 1]; } } catch (e) { // no search selected, so just don't do anything } return previousRecord; } Previous_Record();I had to stick in the
try/catchthere becausesearchgenerates aReferenceErrorwhen you don’t have a Saved Search selected if you try to reference it.Anyway, so without having to manipulate the user interface, you can get the previous record using the above technique.
January 1, 2020 at 12:30 PM #39053In reply to: Issues with very basic Field Script Output
Sam Moffatt
ParticipantI created a new form with the three fields, created a new script field, pasted your script in, changed the field ID’s around and it worked out of the box for me. Tested on TF 5.3.9 (Build 955) from MAS.
The
Can't find variable: recorderror I know happens with form scripts from time to time and if you’re working in the script editor I have seen it get disconnected from state though I’ve never been able to reproduce it consistently. The one I run into from time to time is thatformisn’t a variable for my form script however closing the script editor and re-opening it seems to reconnect everything for me.If you’re still getting the hang of Javascript, Humble Bundle have a book bundle including “Javascript: The Good Parts” for their $1 tier. I came to JS a little earlier than the book, so I’ve never read it but I’ve had plenty of folk I trust who have read it that found it useful. It’s available as a part of the O’Reilly Classics bundle over at Humble Bundle. Humble do books in generally PDF, Mobi and ePub.
-
AuthorSearch Results