Copy link to clipboard
Copied
Hi,
I have a two text boxes, one is the users input for a serial number and the other text box checks what was writtin as a serial number and changes what is written in it depending on the range. the serial numbers are like this:
AHB15000 - AHB15999
BHB15000 - BHB15999
CHB15000 - CHB15000
as there is a serial number break at KHB15103 everything before should say one thing and everything after should say something else. Other than writing the following code im not sure what to do:
else if (/KHB15000/.test(s)) event.value = "option 2";
else if (/KHB15001/.test(s)) event.value = "option 2";
else if (/KHB15002/.test(s)) event.value = "option 2";
else if (/KHB15003/.test(s)) event.value = "option 2";
etc.
Sorry im quite new to this so dont have a huge amount of knowledge!
this is the code I am useing:
var s = this.getField("Serial No").valueAsString; // insert actual field name
if (/KHB15//.test(s)) event.value = "Option 1";
else if (/MHB15/.test(s)) event.value = "option 2";
else event.value = "TEST";
Thank you
Hi,
In accordance with your table you sent me, here is a custom keystroke script which allows to only type a serial number at a correct format and display the corresponding torque:
function displaying(theValue) {
if (theValue.length!="ABCD12345AHB15000".length) this.getField("torque").value="";
else {
if (/HB15\d{3}/.test(theValue)) {
if (/[A-J]HB15\d{3}/.test(theValue) || /KHB1500[0-3]/.test(theValue)) this.getField("torque").value="1230Nm";
else this.getField("torque").value="1570Nm"
...
Copy link to clipboard
Copied
Hi,
Could you try to explain a bit better because at the moment I don't understand anything at all...
@+
Copy link to clipboard
Copied
Hi,
Sorry it is a bit convolutated!
So I have a form for checking machinary. This form is used by engineers. Each time the engineer fills out the form they must put the serial number in a text box at the top of the page ("Serial No"). there are several textboxes for the enginner to coment in on the page. One of these (the text box in question) tells the enginner a tourqe rating required for a bolt.
depending on the machine/ serial number the tourque rating can change. A complete serial number looks something like this: ABCD12344AHB15000. this can be broken down to look like this though:
ABCD Manufacturer
12344 Machine Model
A Model year
HB15 Also machine model
000 Machine number off the production line
so the issue I am having is the tourqe rating for a bolt is 1200 Nm form AHB15000 to KHB15103 and 1600 Nm form KHB15104 onwards.
I can get the text box in question to search the "Serial No" textbox for items such as AHB15XXX AND CHB15XXX etc. fine but other than writing the following from 000 to 103 then 104 to 999 (code shown below) I dont know of a simpler way to do it. Im not sure its very efficient for the code to have 1000 lines for differnet serial numbers!
else if (/KHB15000/.test(s)) event.value = "1200Nm";
else if (/KHB15001/.test(s)) event.value = "1200Nm";
else if (/KHB15002/.test(s)) event.value = "1200Nm";
etc.
else if (/KHB15104/.test(s)) event.value = "1600Nm";
else if (/KHB15105/.test(s)) event.value = "1600Nm";
else if (/KHB15106/.test(s)) event.value = "1600Nm";
etc
Hopefully this make more sense! if not let me know please!
Thank you
Copy link to clipboard
Copied
View the unit, I guess you want to say "torque" instead of "tourque"... 😉
If I understand well, you should only write:
if (/[A-J]HB15000/.test(s) || /KHB1500[0-3]/.test(s)) event.value = "1200Nm";
else event.value = "1600Nm";
@+
Copy link to clipboard
Copied
Hi,
Yeah that might be the right spelling! haha
so from my limited understanting this puts 1600 Nm if A-J (and part of K) isnt found, I would like it to say "please check service manual" if it cannot find any of the serial number parts, will this do that? or would i need to put something like the following in?
if (/[A-J]HB15000/.test(s)) event.value = "1200";
else if (KHB1500[0-3]) event.value = "1600";
else event.value = "TEST";
Thank you
Copy link to clipboard
Copied
After re-reading of your previous messages, try that and let me know if that answers to your request:
if (/HB15\d{3}/.test(s)) {
if (/[A-J]HB15\d{3}/.test(s) || /KHB1500[0-3]/.test(s)) event.value = "1200Nm";
else event.value = "1600Nm";
} else event.value="Please check service manual";
@+
Copy link to clipboard
Copied
Hi,
Yes that does seem to work well. the next issue I have is that (which i should have been more specific about before! Sorry!!) one particualar machine model is 15 i.e. KHB15000 (as stated before) there are also machines that have the following numbers instead of the 15
01, 02, 03, 04, 05, 07, 11, 12, 13, 14 and 17
The other issue with these is that some will not have a serial number break!
However will these will be in the same layout as the previous started serial numbers. I can get it to work by doing something like the following:
var s = this.getField("Serial No").valueAsString;
if (/HB15\d{3}/.test(s)) {
if (/[A-J]HB15\d{3}/.test(s) || /KHB1500[0-3]/.test(s)) event.value = "1200Nm";
else event.value = "1600Nm";}
else if (/HB17\d{3}/.test(s)) {
if (/[A-J]HB17\d{3}/.test(s) || /KHB1700[0-3]/.test(s)) event.value = "1300Nm";
else event.value = "1700Nm";
}
else event.value="Please check service manual";
will I need to do that for each number?
Thank you, and sorry for being a pain!!
Copy link to clipboard
Copied
Which numbers have a break?
only 15 and 17?
...and what are the torque for each number ?
Copy link to clipboard
Copied
Hi,
I have sent you a message with the serial number breaks and the torque settings
Thank you
Copy link to clipboard
Copied
Hi,
In accordance with your table you sent me, here is a custom keystroke script which allows to only type a serial number at a correct format and display the corresponding torque:
function displaying(theValue) {
if (theValue.length!="ABCD12345AHB15000".length) this.getField("torque").value="";
else {
if (/HB15\d{3}/.test(theValue)) {
if (/[A-J]HB15\d{3}/.test(theValue) || /KHB1500[0-3]/.test(theValue)) this.getField("torque").value="1230Nm";
else this.getField("torque").value="1570Nm";
} else if (/HB1(1|2|3|4|7)\d{3}/.test(theValue)) {
if (/[A-J]HB1(1|2|3|4|7)/.test(theValue) || /KHB1(1|2|3|4|7)00[0-3]/.test(theValue)) this.getField("torque").value="1355Nm";
else if (/HB1(1|2)/.test(theValue)) this.getField("torque").value="1355Nm";
else if (/HB1(3|4)/.test(theValue)) this.getField("torque").value="1670Nm";
else this.getField("torque").value="1050Nm";
} else this.getField("torque").value="Please check service manual";
}
}
if (!event.willCommit) {
event.change=event.change.toUpperCase();
if (event.value.length=="ABCD12345".length && event.change!="") event.change+="HB";
var aTester=event.value.split("");
aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
var testeChaine=aTester.join("");
if (testeChaine.length<="ABCD12345".length) var RegExSerialNumber=/^([A-Z]{1,4}\d{0,5})?$/;
else if (testeChaine.length<="ABCD12345AHB15".length) var RegExSerialNumber=/^([A-Z]{1,4}\d{0,5}([A-Z](H(B(((0(1|2|3|4|5|7)?)|(1(1|2|3|4|5|7)?)))?)?)?)?)?$/;
else var RegExSerialNumber=/^([A-Z]{1,4}\d{0,5}([A-Z](H(B(((0(1|2|3|4|5|7)?)|(1(1|2|3|4|5|7)?))\d{0,3})?)?)?)?)?$/;
if (RegExSerialNumber.test(testeChaine)) displaying(testeChaine);
else event.rc=false;
} else {
var RegExSerialNumber=/^[A-Z]{4}\d{5}[A-Z]HB((0(1|2|3|4|5|7))|(1(1|2|3|4|5|7)))\d{3}$/;
if (event.value=="" || RegExSerialNumber.test(event.value)) displaying(event.value);
else event.rc=false;
}
Attached is the example file.
@+
Copy link to clipboard
Copied
You say Java, but this is JavaScript. It is very important to get this right, because if you try to get help, and say you use "Java" you will get wrong, confusing, or damaging advice!
Ok, you give us a code fragment. But you don't tell us what you want to happen ("expected result") and what actually happens ("actual result") for different values of Serial No. Also did you check the console for errors? Also, where is this script fragment located (including field and event type).
Copy link to clipboard
Copied
Hi,
Apologies for the Java/ Java script error!
hopefully my last comment will make things slightly clearer! so currently unless you have for example AHB15 in the code the textbox will have "Test" in the textbox. the script is located in "custom calculation script" of the textbox
Thank you