onSubmit Client Script not submitting the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 08:13 AM - edited 02-02-2023 08:14 AM
I have a very simple client script on the cmdb_ci table to make the Model ID field mandatory when creating a new CI record. See attached screenshot and see below for the script:
function onSubmit() {
//if it is a new CI record, then make the Model ID mandatory
if (g_form.isNewRecord()) {
g_form.setMandatory('model_id', true);
return false;
}
}
When I go to create the CI record and click submit, it makes the Model ID field mandatory (which is expected) but when I populate the field and click submit, it does not submit the form. Why is this happening? Any thoughts or suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 04:05 PM
Hi,
The (g_form.isNewRecord) script will always return true and abort the submit. Ideally you would make the field mandatory (UI Policy) before the user submits. If that's not possible, the below script should help:
function onSubmit(){
var mandatoryVar = g_form.getValue('model_id');
if (!mandatoryVar){
g_form.setMandatory('model_id', true);
alert("Model ID is mandatory. Please populate and resubmit the request.");
return false;
}
}