Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
January 23, 2020 at 10:54 AM #39343
In reply to: Linked forms and importing records
Daniel Leu
ParticipantWith
record.addRecordToField()you can link records from a script. The challenge might be to identify matching records.On the other hand, you might be able to define the linked forms using the link type ‘join’. This way the linking is automatic. This works well if both forms have a common reference ID.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksJanuary 22, 2020 at 2:59 PM #39333In reply to: Increment/decrement buttons, like tally counter?
Daniel Leu
ParticipantYou should be able to achieve this with a custom layout. First you would need to create a simple script that increments or decrements the counter field. Then in the custom layout, you create a ‘Run Script Button’ and assign your just created script.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksJanuary 15, 2020 at 9:03 AM #39254In reply to: Time-Format yyyy-mm-dd
Sam Moffatt
ParticipantI think that’s the most elegant way in Javascript. Keeping in mind what you’re working with there is the native Javascript primitives (e.g. toISOString always returns UTC). Most of the recent mentions on the web for Javascript and dealing with date objects will be relevant to Tap Forms as well.
January 15, 2020 at 5:52 AM #39252Topic: 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!
Sonya -
AuthorSearch Results