Form Logic - Custom Function to remove trailing spaces


New Member
Fairly new to TracerPlus development so bear with me. Some of our barcode products end up scanning with trailing spaces which we need to strip out before submitting to the database (ex: "ProductID123 " needs to be "ProductID123" with no trailing spaces). I see that in the Form Logic section there is an option for "Custom Function" which the manual suggests can be used to enter Javascript functions. Seems like this would do the trick (using a "trim" function) but I cannot find any examples by TracerPlus of how the Custom Functions are entered. Are there any examples of custom javascript functions available so I can see how this works?

Or any other simpler method of trimming any leading and/or trailing spaces from a scanned barcode?


Dan Peluso

Staff member

You are correct that we do not have a lot of samples of how to use custom script but I can outline some options here.

1. Instead of Custom Script, you could use the "ExecuteSQL" function to do something like "SELECT RTRIM('[*x*]',' '). In this example, you would replace x with the Field Index of the Field on the form so if it was Field1, it would be [*0*] since these field indices are 0 based.

This would still be done in Formlogic and you can fire it on a field value changed or after scan event. Typically, putting this result into a different field(control ID) would be a best option to prevent it firing multiple times.

2. You could also do as you suggest using Form Logic and the Custom Function. I will leave the JS to you but you can reference the html object based on its Session Index and control id. For Session1 and a control Id of 15, you could use something like
var pControl = document.getElementByID("00-15");

From there, you can do anything you like at the Javacript level. I do think the first option may be easier but that is up to you.

Let me know if that helps


New Member
Thank you for the suggestions. Sounds like the ExecuteSQL would be a much simpler solution. I'll look into doing it that way first.