trim data in a form field after the form is submitted.

ZacCantrail
Tera Contributor

I am needing to make sure a specific field on a form gets trimmed when the form is submitted. I have a field in my form named 'asset tag' i need to make sure that this field has no leading or trailing blank spaces. Now I imagine i could just set up a rule of some sort to run a script when ever the form is submitted to trim the value that was entered. My question is can i use the JavaScript trim function in ServiceNow, and what would the field reference look like?

2 REPLIES 2

Elijah Aromola
Mega Sage

You could just run the code onSubmit or in a before business rule. Just do a .trim() on the field. 

// onSubmit script

var value = g_form.getValue('field_name');
g_form.setValue('field_name', value.trim());

// before business rule

current.field_name = current.field_name.trim(); 

Please mark this as correct/helpful if it answered your question!

Prateek kumar
Mega Sage

Sure you can.

Configure a before business rule and trim down the field value. Something like this

var final = current.YourVariablename.trim();

current.YouVariablename = final;

https://docs.servicenow.com/bundle/newyork-application-development/page/script/business-rules/task/t...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks