
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 07:53 AM
I have an on change script where I populate a file based on a p[previous selection. The populated field is mandatory.
How do I default the field to include none as the default and still make it mandatory to select?
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}
//remove all items from type
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('type');
//build a new list of dependent options
var gp = new GlideRecord('u_pshr_account_access_lookup');
gp.addQuery('u_string_1', newValue);
gp.addOrderBy('u_string_2');
gp.query(function (gp){
while(gp.next()){
g_form.addOption('type', gp.u_string_2, gp.u_string_2);
}
});
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 08:58 AM
Hello Mark,
Include setValues and Mandatory after while loop and check once.
while(gp.next()){
g_form.addOption('type', gp.u_string_2, gp.u_string_2);
}
g_form.setValue('type', '');
g_form.setMandatory('type',true);
Note: Untested
-Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 08:58 AM
Hello Mark,
Include setValues and Mandatory after while loop and check once.
while(gp.next()){
g_form.addOption('type', gp.u_string_2, gp.u_string_2);
}
g_form.setValue('type', '');
g_form.setMandatory('type',true);
Note: Untested
-Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 09:51 AM
Perfect solution, thank you.