Copy link to clipboard
Copied
I'm creating a PDF form to be used in a blood bank. When I scan a number, from a blood bag, how can I convert it to text? For instance, I want the numbers "5100" to convert to "O Pos". Is there a Javascript that can do that?
Let's say the field with the numbers is called Text1, and the field where the text should appear is called Text2.
Use something like this as the custom calculation script for Text2:
var t1 = this.getField("Text1").valueAsString;
if (t1=="5100") event.value = "O Pos";
else if (t1=="5200") event.value = "O Neg";
else if (t1=="5300") event.value = "A Pos";
else if (t1=="5400") event.value = "A Neg"; // etc.
else event.value = "";
Of course, I just made up the values above... Replace them with the real ones
...Copy link to clipboard
Copied
Do these numbers appear in a form field? If so, then it can be done using a custom calculation script, yes.
Copy link to clipboard
Copied
Yes, they are scanned into a form field. Can you post the custom calculation script? Thanks!
Copy link to clipboard
Copied
Let's say the field with the numbers is called Text1, and the field where the text should appear is called Text2.
Use something like this as the custom calculation script for Text2:
var t1 = this.getField("Text1").valueAsString;
if (t1=="5100") event.value = "O Pos";
else if (t1=="5200") event.value = "O Neg";
else if (t1=="5300") event.value = "A Pos";
else if (t1=="5400") event.value = "A Neg"; // etc.
else event.value = "";
Of course, I just made up the values above... Replace them with the real ones in your actual code.
Copy link to clipboard
Copied
Thank you for sending the script. Must I create two different fields, or is there a way to scan into a single field, and have the interpretation show up in that same field? Or, can I overlay the two fields somehow? This is a screen shot of the current form. I don't like the drop down menu under the Blood Type column because it can't be scanned like the two fields prior to it in the same row (I already inserted a script to auto-tab from one field to the next). I want to scan the blood type ("5100") in the "ABO1" field and have the interpretation of "O Pos" show up in the same spot (and then auto-tab to the next row). Is that possible?
Copy link to clipboard
Copied
I would use two fields. The first one can even be hidden.
Copy link to clipboard
Copied
OK. How do I hide the first field?
Copy link to clipboard
Copied
I'm obviously not a software engineer, I'm a clinical laboratory scientist, so I'm doing my best to understand the details, but I am an amateur at best. I inserted the real ABO values in the code, and deleted the "// etc." Was is correct to deleted the "//"? And, when I paste it into the form, do I need to delete the numbers at the beginning of each line?
Copy link to clipboard
Copied
I asked those questions too soon. I figured out how to hide the field, and to delete the numbers at the beginning of each line. Thank you again, for that script!
Here is another question, though. Can you write me a script that cleaves off the beginning character of whatever is scanned? For instance, when I scan a blood identification number that is supposed to be W123456789123, it shows up as =W123456789123. I want to automatically remove the "=". Thanks!
Copy link to clipboard
Copied
The problem is I'm not sure what kind of events the scanning processes triggers... If it's the same as entering the value manually into the field then you can use this code as the custom validation script:
event.value = event.value.replace(/^=/, "");
Copy link to clipboard
Copied
Yes, the scanning process triggers the same event as entering the value manually. I will try this script.
Back to the original script. I can get it to convert the numerical value to the alphabetic value, but only when I'm editing the Text field properties. I falsely assumed that it would work as I was scanning it. I added the following script as a Custom Keystroke Script to move the cursor from one field to the next:
// Autotab to the "Comp Code Row1" field
tab_next("Comp Code Row1");
And it works for all the fields except for the ABO1 field. Why would it only do the conversion when I'm editing it, and not after I've closed the form editing mode?
Copy link to clipboard
Copied
Because that doesn't trigger any events. The calculation event is only triggered when the value of a field is changed, or if you call the calculateNow method of the Document object.
Copy link to clipboard
Copied
Hello try67,
You helped me a few years ago with a Javascript for a PDF fillable form I was working on. Could you help me again? I'm looking for a custom Javascript that converts a time stamp to a regular date. I intend to use this in a PDF form to scan the expiration date of blood products. When I scan the timestamp barcode on the blood product, this is what I get: "&>0231512359". I already have a custom script that cleaves the "&>" and tabs to the next field in the PDF form. I just need a script that turns the 10-digit Julian (is that the correct term?) date to a regular MM/DD/YYYY format. I've tried various scripts I found on message boards, but none have worked so far. Can you help me with this? Thanks in advance!
Copy link to clipboard
Copied
Ok, thanks for the clarification. I appreciate all your help!