Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
January 12, 2022 at 5:31 PM #46287
In reply to: Find filename of an image
Brendan
KeymasterHi Daphne,
The Field Script that Daniel wrote for you does exactly what you describe.
Did you adjust the
photo_idvalue in the script to match up with the ID of the Photo field in your own form?When you said it didn’t work for you, what exactly happened? Were there any error messages in the console log?
Thanks,
Brendan
January 12, 2022 at 12:03 PM #46285In reply to: Find filename of an image
Daphne Tregear
ParticipantThanks for your reply. I am unable to get it to work and I may not have described my problem well enough. Please bear with me.
I am creating my PDF by using the Print menu to save a PDF of a selection of database fields to a file on my system. This file, plus a copy of the images directory my database references, will be written to a flash disc and sent by post to someone. The person can then peruse the PDF and refer to the images if they wish. There may not be an image associated with every record, so the script must be able to cope with that.
Where a record does have one or more associated images my field called “Image” shows the image(s). I wish to set up a new field in each record (let’s call it “Image name”) which shows the filename of the image(s) (just the filename not the complete path). I can then include “Image name” on my printout so the recipient knows which filename to look at.
Does that make it clearer?
January 12, 2022 at 10:18 AM #46281In reply to: Find filename of an image
Daniel Leu
ParticipantI assume that all your PDFs are either
file attachmentsorphotos. This field script extracts the filenames and returns them as a comma separated list.You would need to adjust the
photo_idfield according to your form. Just get the id of thefile attachmentorphoto attachmentfield.function Get_Filenames() { const photo_id = 'fld-xxx'; let filenames = [] let photos = record.getFieldValue(photo_id) console.log("Found photos:" + JSON.stringify(photos)); for (photo of photos){ filenames.push(photo.filename); } return filenames.join(', ') } Get_Filenames();-
This reply was modified 4 years, 3 months ago by
Daniel Leu.
-
This reply was modified 4 years, 3 months ago by
Daniel Leu.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksJanuary 9, 2022 at 11:19 AM #46268In reply to: Service order with inventory mod
Sam Moffatt
ParticipantI did a tutorial on managing balances with Tap Forms using yarn balls as an example and products like hats. There are two videos, the first video sets the ground work forms and has a simple script for setting the balance whilst the second video walks through building the scripting to add and remove entries maintaining the balance. These should help you handle reducing the inventory quantity when applying new parts but it does rely upon form scripts to work properly.
January 9, 2022 at 1:24 AM #46267In reply to: Service order with inventory mod
Brendan
KeymasterHi Justin,
Can you please include your Inventory Parts and Customer forms too? They weren’t included within the Service-Order form.
When I look at the List formula, all I am seeing is:
/(1-.30). Perhaps it didn’t come through in the archive or maybe it was just like that in the original. Not sure.I would also prefix the
.30with0. So(1 - 0.3). The trailing 0 is insignificant and not required.For reducing the inventory quantity you would have to add a Field Script that gets the value of the
Qtyfield and then looks up the part from the Inventory Parts form and then subtracts the value from there. It would take a bit of work.Thanks,
Brendan
January 8, 2022 at 9:57 PM #46264Topic: Service order with inventory mod
in forum Using Tap Forms 5Justin Dalton
ParticipantWorking on a service order database with a live inventory. I am new too scripting and am just starting to do the basics. I have created this database without scraping, I wouldn’t mind adding it but just don’t know enough. So… with that said if the answer to my question lies within scripting than I will have a bunch of questions. I currently have 2 issues that I am sorting out at the current moment, any help would be greatly appreciated.
First issue,
I have created a form called “Inventory Parts” that I have entered information on an Item. Things like: Part #, Name, Price, Qty in stock. then I have created another form called “Service Order” which has a table that copies records from “Inventory Parts” form. I have created another field in the table that has the copied data that I have named QTY. Then I created another field that I called “Sub Total” that contains a formula (Qty*List). When using the copied data in the field and using the formula the copied List price turns to $0.00 and I am unable to use the expression to fill the sub total.
Second issue,
I can’t for the life of me figure out how to reduce the inventory qty after the part is added to a service order.
Thanks in advance, I have tried paid programs and can’t seam to find what I want. This is why I have moved to building my own through tap forms.
Attachments:
You must be logged in to view attached files.January 7, 2022 at 11:05 PM #46259In reply to: How to do a “Grand Total” across all records.
Sam Moffatt
ParticipantIn the script editor, make sure the return type is set to be a number in addition to the number format setting in the field settings. The default for script fields is text.
January 7, 2022 at 3:39 AM #46252In reply to: How to do a “Grand Total” across all records.
Brendan
KeymasterAlternatively if you click the ID button on the Script Editor, you’ll get a variable assigned to the Field ID of the selected field. Then you can use that in the
getTotalOfField()function.I prefer to see the Field IDs as separate things because when you look at the code it’s hard to see what field you’re getting the total from.
For example:
var order_cost_id = 'fld-acdbf6132877436d8f86d12a7a732a13'; var order_cost_total = form.getTotalOfField(order_cost_id);I know it’s two lines instead of one, but it’s easier to read then.
January 7, 2022 at 12:58 AM #46250In reply to: How to do a “Grand Total” across all records.
Sam Moffatt
ParticipantCreate a new script field, delete all of the boilerplate it creates and then double click on the field you want to total, it should look like this:
var order_cost = record.getFieldValue('fld-acdbf6132877436d8f86d12a7a732a13');Delete the text before
record.getFieldValueand replace it withform.getTotalOfField, it should look like this:form.getTotalOfField('fld-acdbf6132877436d8f86d12a7a732a13');The exact text of the
fld-stuff will be different based on your actual field.January 6, 2022 at 2:55 PM #46245In reply to: Add Record Details – Table Control Not Working
Sam Moffatt
ParticipantI think you’d need to set the value of the fields referenced by the calculation field because otherwise a recalc will reset the field value anyway. I wonder if there is some sort of data race between setting the value and then the record creation triggering the calc/script fields to be run as well. That would work ok for calculation fields for the composite key use case but I can see if someone joined on a script field that might be a little more challenging as well.
Would it make sense to block the UI if someone uses a calculation or script field in a JOIN?
January 5, 2022 at 2:57 AM #46227In reply to: Add Record Details – Table Control Not Working
Sam Moffatt
ParticipantIt might still be creating the blank record but when it loads in the list view that record is excluded because a blank record likely doesn’t meet your JOIN criteria because it’s
Lot #field isn’t set. When you’re in the list of linked records, the new record button works because TF hasn’t recalculated the record list yet, it is just inserting the newly created record into the view. Though when this happens if a recalculation happens, that record will disappear from the list if it doesn’t satisfy the JOIN field criteria.Ideally if you want to use TF to create the records then the JOIN type really isn’t a good fit as you have to manually ensure the correct value is set. JOIN is great for piecing together externally linked data though. One other workaround I personally use is a script that creates linked records with the correct values set for the link to work properly (important when using calc fields to JOIN on composite keys).
December 27, 2021 at 10:16 PM #46198In reply to: Change field value based on other fields
Brendan
KeymasterAnother idea since it’s a simple lookup table would be to use an array and just use the grupo value to index into the array.
function Script_Precio() { var precio_lookup = [62, 90, 125, 157, 250]; // array indexes start at 0, so subtract 1 from grupo var grupo = record.getFieldValue('fld-6c980123a15646a085389ac4426e07de') - 1; var company = record.getFieldValue('fld-e1c28abdd3b8451fa38b875818503bc6'); if (company == "TEST") { if (grupo < precio_lookup.length) { var precio = precio_lookup[grupo]; record.setFieldValue('fld-5b32e56f61f34bfb8e9c522f9eb9414a', precio); document.saveAllChanges(); } } return; } Script_Precio();But I don’t know exactly what your data looks like. Maybe this would work for you, maybe the switch statement is better. Not sure.
-
This reply was modified 4 years, 4 months ago by
Brendan.
December 27, 2021 at 2:45 PM #46195In reply to: Change field value based on other fields
Brendan
KeymasterHi Guillermo,
FYI, if you surround your code with the back tick character, then your code will be formatted more nicely and will be easier to read, like in Daniel’s example.
function Script_Precio() { var grupo = record.getFieldValue(‘fld-6c980123a15646a085389ac4426e07de’); var precio var company = record.getFieldValue(‘fld-e1c28abdd3b8451fa38b875818503bc6’); if (company==”TEST”) { // Grupo 1 if (grupo==1) { precio=62 } //Grupo 2 if (grupo==2) { precio=90 } // Grupo 3 if (grupo==3) { precio=125 } // Grupo 4 if (grupo==4) { precio=157 } // Grupo 5 if (grupo==5) { precio=250 } } record.setFieldValue(‘fld-5b32e56f61f34bfb8e9c522f9eb9414a’, precio); document.saveAllChanges(); } Script_Precio();Also, a
Switchstatement might be a little nicer:function Script_Precio() { var grupo = record.getFieldValue('fld-6c980123a15646a085389ac4426e07de'); var precio; var company = record.getFieldValue('fld-e1c28abdd3b8451fa38b875818503bc6'); if (company == "TEST") { switch(grupo) { case 1: precio = 62; break; case 2: precio = 90; break; case 3: precio = 125; break; case 4: precio = 157; break; default: precio = 250; break; } record.setFieldValue('fld-5b32e56f61f34bfb8e9c522f9eb9414a', precio); document.saveAllChanges(); } Script_Precio();-
This reply was modified 4 years, 4 months ago by
Brendan.
December 26, 2021 at 1:16 PM #46192In reply to: Change field value based on other fields
Guillermo q
ParticipantOk I did it. Thank you very much.
function Script_Precio() {
var grupo = record.getFieldValue(‘fld-6c980123a15646a085389ac4426e07de’);
var precio
var company = record.getFieldValue(‘fld-e1c28abdd3b8451fa38b875818503bc6’);
if (company==”TEST”) {
//Grupo 1
if (grupo==1) {
precio=62
}//Grupo 2
if (grupo==2) {
precio=90
}//Grupo 3
if (grupo==3) {
precio=125
}//Grupo 4
if (grupo==4) {
precio=157
}//Grupo 5
if (grupo==5) {
precio=250
}}
record.setFieldValue(‘fld-5b32e56f61f34bfb8e9c522f9eb9414a’, precio);
document.saveAllChanges();
}
Script_Precio();
December 26, 2021 at 11:56 AM #46190In reply to: Change field value based on other fields
Sam Moffatt
ParticipantMake sure you have a record selected before running the form script. On iOS this means you have to navigate into the record before running the script (you can’t run form scripts from the record list view, only record detail). On the other platforms, simply making sure a record is selected and displayed should be sufficient. It’s a little harder on the Mac to not have a record select but still possible.
-
This reply was modified 4 years, 3 months ago by
-
AuthorSearch Results