Hi 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 .30 with 0. 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 Qty field 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
Working 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.
In 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.
Alternatively 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.
Create 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.getFieldValue and replace it with form.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.
I 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?
It 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).
Another 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 ago by
Brendan.
Hi 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 Switch statement 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 ago by
Brendan.
Ok 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();
Make 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.
Hello, Merry christmas to everyone,
I tried to write an script to change the field value based on other fields. I created an script in the form but I cant find which is the problem. Can you help me?
function Script_Precio_Y_Grupo(){
var company = record.getFieldValue(‘fld-e1c28abdd3b8451fa38b875818503bc6’);
var grupo = record.getFieldValue(‘fld-6c980123a15646a085389ac4426e07de’);
var precio
if (company==”TEST”) {
//Grupo 1
if (grupo=1) {
precio=62
}
//Grupo 2
if (grupo=2) {
precio=90
}
//Grupo 3
if (grupo=3) {O
precio=125
}
//Grupo 4
if (grupo=4) {
precio=157
}
//Grupo 5
if (grupo=5) {
precio=250
}
}
record.setFieldValue(‘fld-5b32e56f61f34bfb8e9c522f9eb9414a’, precio);
form.saveAllChanges();
}
Script_Precio_Y_Grupo();
The other thing that makes this increasingly difficult is that out of the box MacOS is removing support for the scripting languages that it used to ship by default so getting back PHP on the Mac is increasingly hard.
I haven’t written any write to disk API for the scripting engine, but I should definitely do that.