How to check the mandatory field that contains default value, is added or not through Client Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 10:22 PM
I have a field in a table which is mandatory field.
Now I have provided a default value for that field. But I want User to fill that field.
it should be like default value will be there and user should suppose to fill that mandatory. Or else the form should not submit.
How do I do this via client script 'onSubmit'?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 10:29 PM
Hi - You can do this via OnSubmit client script. Refer below blog for reference on how to check if the field is modified or not.
https://www.servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 10:31 PM
Sample script:
var field1 = g_form.getControl('PASS FILED NAME HERE'); //Get the 'Caller' field control
if(field1.changed && field1 != 'PASS DEFALUT VALUE HERE'){
return true;
}
else
{
return false;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 08:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2020 10:54 PM
you can try to use combination of display BR and onsubmit client script
Display BR: on your table it will store the default value when it is new record
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.isNewRecord()){
g_scratchpad.value = current.field_name;
}
})(current, previous);
onSubmit client script:
function onSubmit(){
if(g_form.isNewRecord()){
if(g_form.getValue('field_name') == g_scratchpad.value){
// it means user has not changed the default value to some other value
alert('Please change the default value for field');
return false;
}
return true;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader