trim data in a form field after the form is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 12:25 PM
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?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 12:31 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 12:32 PM
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;
Please mark my response as correct and helpful if it helped solved your question.
-Thanks