Validating Reference Field Value in Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a form where caller_id is a reference to the sys_user table. The user's mobile phone is displayed on the form as a reference field (not a separate database field), and the user can edit it before submitting. Since g_form.getValue() doesn't work for this reference field, g_form.getReference() returns only the saved database value, and GlideAjax also reads only saved data, what is the recommended ServiceNow approach to validate the edited mobile phone number in an onSubmit client script before the record is saved?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @sairajyadav,
If the dot-walked field must remain directly editable on your form, validate the value at the database level when it is submitted:
Create an onBefore Update Business Rule on the sys_user table.
Set the condition to run when the Mobile phone field changes.
Validate the format in your script. If it fails, use gs.addErrorMessage() and current.setAbortAction(true) to cancel the save and display the error to the user.
If you found this response useful, please mark it as Helpful and accept it as the Solution to help others with similar questions.
Best regards,
Mariam Ahmed.