Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
November 26, 2018 at 12:58 PM #32114
In reply to: Scripting conditionals involving lists
Federico Martinez
ParticipantThere are many ways to do this. first you need to specify which episode belongs to which trilogy in here I chose a table within the form because I think its just easy using the specified fields.
After setting up pick list SS1
and Setting up form with table SS2this code on script SS3:
I am pretty new to tapforms and there maybe better ways to do this. also you need to replace the field value ID’s with the ones in your own script by pulling them from the available fields.// initial variables var episode = record.getFieldValue('fld-9e272cfa06144cfe94f46639cc4d651d'); var table = record.getFieldValue('fld-fd2390f763264167809191f09badbbd2'); //default no match variable in case it is not found. var result = "no match" // for loop to search for a match for (var index = 0, count = table.length; index < count; index++){ // table variables var episodes = table[index].getFieldValue('fld-8b366549607a4664a2ad3cf9b77676f3'); var trilogy = table[index].getFieldValue('fld-05603762b3ec47e19cedd2f0c1abc1a3'); // if it finds match returns it. if (episodes == episode) { console.log(trilogy) result = trilogy } else { // false condition; } } result;you can hide the table in the form SS4
Attachments:
You must be logged in to view attached files.November 26, 2018 at 7:02 AM #32098In reply to: Scripting conditionals involving lists
Kay Beckham
ParticipantTo help save some time, I’ve attempted to write the code on my own by copying and pasting from other tutorials online.
`var featured_series_id = ‘fld-1410861e610c4cba9abd7683e74d030d’;
var StarWarsMovie = record.getFieldValue(featured_series_id);
var StarWarsTrilogy;switch (StarWarsMovie)
{
case ‘Episode 1’:
case ‘Episode 2’:
case ‘Episode 3’:
something something Prequel Trilogy
break;
case ‘Episode 4’:
case ‘Episode 5’:
case ‘Episode 6’:
something something Original Trilogy
break;
case ‘Episode 7’:
case ‘Episode 8’:
something something New Trilogy
break;So this is where it gets confusing. In the “Edit Field Script” window, I don’t see the option for the field that will run this script. I want the field to show those labels, but I’m kind of at a loss on how to make this happen.
November 26, 2018 at 6:27 AM #32097In reply to: Frequency of field script execution?
Federico Martinez
Participantvar transfers = document.getFormNamed('Transfer requests'); var pending_id = 'fld-ed603b4c67b14e829a2d96e5d3cab22c'; var no_match_id = 'fld-7dcda80275e74246bf0bc3bcb5b6db86'; var records = transfers.getRecords(); for (var index = 0, count = records.length; index < count; index++){ var pend = records[index].getFieldValue(pending_id); if (pend) { console.log("true"); records[index].setFieldValue(no_match_id, true);So this won’t execute a script on form “transfer requests”?
is there a way to call on a script or formula to execute from another script?Thanks
November 26, 2018 at 6:17 AM #32096Topic: Scripting conditionals involving lists
in forum Using Tap Forms 5Kay Beckham
ParticipantHello. I would like some scripting help with a database I’m creating.
What I would like is to take the contents of a pick list, compare them with a different list (it can be within the script, or it can be referred from somewhere else, doesn’t matter), and then show the entry that matches the conditions. I’ve created a pick list in the preferences of my database.
To use an example, the pick list has Star Wars Episode 1 to 8. The other list has three entries: Prequels, Original Trilogy, New Trilogy. So if Episode 2 is selected from the pick list, the Script field would show “Prequels”.
Is this possible?
November 25, 2018 at 9:48 PM #32071In reply to: Mileage Tracker (Tap Forms 5.3)
Ryan M
ParticipantThought I’d play around and see if I could come up with a different approach to the same mileage tracker. This would probably be closer to a fuel log rather than a simple mileage tracker.
The inputs would be:
– odometer value
– Price per gallon
– Gallons filledA script would calculate your mileage since last fill up as well as your miles per gallon.
The script uses the default created date field to sort all records by their created date. This assumes that you’re entering in your mileage log around the time you filled up.
Here’s the script for those interested
var odometer_id = 'fld-9674e316bfed408ca6710ce81b72bf05'; var vehicle_id = 'fld-64b0b17a635f49b8b40867e45f8d24db'; var date_created_id = 'fld-2097149a2eeb4d4e892f13b62de6b5ea'; // sort records in ascending order by date value var dateSorter = (a, b) => a.getFieldValue(date_created_id) - b.getFieldValue(date_created_id) var run = () => { var vehicle = record.getFieldValue(vehicle_id); var odometer = record.getFieldValue(odometer_id); var records = form.getRecords() .filter(r => r.getFieldValue(vehicle_id) === vehicle) .sort(odometerSorter) var odometerValues = records.map(r => r.getFieldValue(odometer_id)); var currentRecordIndex = odometerValues.indexOf(odometer); var previousRecordIndex = currentRecordIndex === 0 ? 0 : currentRecordIndex - 1 var mileageValue = odometerValues[currentRecordIndex] - odometerValues[previousRecordIndex] return mileageValue; } run();Attachments:
You must be logged in to view attached files.November 25, 2018 at 9:06 PM #32065In reply to: Frequency of field script execution?
Brendan
KeymasterHi Federico,
The scripts only get executed on the same form they’re referenced from. It happens when you call
setFieldValue(field_id, value);I don’t traverse all of the linked fields to execute script fields on them.November 25, 2018 at 8:40 PM #32064In reply to: Frequency of field script execution?
Federico Martinez
Participantif that field being edited is referenced. If so, then it executes that script.
Hi Brendan,
But this does not happen if it is edited from another script right? or at least not one in another form?
right now I was trying to do scripts between 3 forms an independent scoring form, a capture form and a brain form that does what I need it to do. they all work great independently but to see the changes I have to wait until its done and then hit the refresh records for the other scripts to do their things. In my capture form its not a big deal but it is in my scoring form. I am taking advantage of the “link to form join” I can go around this by making more functions on the brain side and duplicating the other scripts. just wanted to make sure this is intended and not a bug.
Thanks!!
November 10, 2018 at 4:34 PM #31740Ron
ParticipantIt is a many to many. The script returns the correct value but when looking at the console log it gives the error.
November 10, 2018 at 11:05 AM #31738Ron
ParticipantAfter refreshing the record single column list the script field displays the correct result. The console log continues to display the same error.
November 10, 2018 at 9:41 AM #31737Ron
ParticipantThanks for the example. I was able to adapt it to my form and when I run the script it returns the expected result, but it is not displayed in the script field on the layout. The console log returns this error:
s_Doc: TypeError: undefined is not an object (evaluating ‘med_doctor[0].getFieldValue’), column:25, line:3
s_Doc is the name of the script field.var med_doctor = record.getFieldValue('fld-84c907c7af3c49daa19ca1e30975bc1b'); if(med_doctor){ var Name = med_doctor[0].getFieldValue('fld-b1cfe8adec9b4d7397683b068a262cc2'); Name; }med_doctor is the parent form and the var Name receives the correct value from the Name field of med_doctor.
The error does not show in the script edit window when the run button is clicked, it only shows in the console if I click the save button and then open the log.November 9, 2018 at 8:33 AM #31733Ron
ParticipantI have attempted to create a script field to return the value from a parent record without success. Could you please give a sample of your script.
Thanks,
RonNovember 8, 2018 at 3:56 PM #31726Brendan
KeymasterHi Deborah,
The reason this doesn’t work the way you would like it to is because a Join Link Type works basically the same way as a Many to Many. That is, you can actually have multiple parent records that all join to the same set of child records using the Join fields.
So that means that a child cannot get access to just one parent record via the Calculation field.
However, this is possible by using a Script field and having Tap Forms get the first parent record from the array of parent records and then picking out the value for the field from the parent record.
November 7, 2018 at 11:48 AM #31692In reply to: get attachment file name with script
Brendan
KeymasterAh yes. The
form.getFieldIds()method. I forgot about that.You’ll see the File Attachment fields in your form appear on the left panel on the Script editor after the next update.
November 6, 2018 at 11:57 PM #31681In reply to: get attachment file name with script
Brendan
KeymasterWell, it is still needed it seems. I’m not sure why yet. Because an NSArray in Objective-C is supposed to translate into a JavaScript array. But an NSDictionary just translates to a JavaScript Object, which I guess still needs to be stringified.
November 6, 2018 at 5:56 PM #31671In reply to: get attachment file name with script
Daniel Leu
ParticipantI was wondering how to get to the attachment ID…
Following scriptlet shows the filename of the first attachment.
var receipt_attachment_id = 'fld-8bbc0b1472a746cabc38f6d7ab045668'; var receipt = record.getFieldValue(receipt_attachment_id); JSON.stringify(receipt); var meta = receipt[0]; if (meta) { meta.filename }Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks -
AuthorSearch Results