Onchange client script is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All ,
I have written the on change client script on the account field , on the first time this script is working fine but in the second time changing the field value ( giving more than 9 digits ) it is not clearing the value , could you please help me on this script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^\d{1,9}$/;
if (!regexp.test(newValue)) {
g_form.showFieldMsg(
'account_number',
'Account number must contain a maximum of 9 digits.',
'error'
);
g_form.setValue('account_number', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar @Tanushree Maiti it is working fine in ITIL view or normal view but it is not working in workpsce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Ensure UI Type of your client script has been set to ALL
Refer: KB0827632 How to configure a client script to run in both platform UI and Workspace
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
things to check
-> is UI type - ALL
-> did you mention particular view in the view field on client script
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Try this-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('account_number' ,true);
var regexp = /^\d{1,9}$/;
if (!regexp.test(newValue))
{
g_form.showFieldMsg('account_number','Account number must contain a maximum of 9 digits.','error');
g_form.clearValue('account_number');
}
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @chandan86patra
Use setValue before showFieldMsg as your code is correct:
Validation Results
SOW:
Native UI:
Hope that helps!
