How to make fields mandatory in client script once the other field is filled?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 01:47 AM
Hi All,
I had a requirement to make the fields on the incident form as mandatory based on other fields(multiple fields ) populated.
I have written a onload client script
function Onload {
//Type appropriate comment here, and begin script below
var a = g_form.getValue('assignment_group');
var mjr = g_form.getValue('major_incident_state');
var al = g_form.getValue('u_incident_started');
var b = g_form.getValue('u_alert_reported');
var c = g_form.getValue('u_on_call_notified');
var d = g_form.getValue('u_required_group_engaged');
var e = g_form.getValue('u_corrective_action_determined');
var f = g_form.getValue('u_system_at_a_useable_level_incident_ended');
var g = g_form.getValue('u_checkout_completed');
if ((a == '83581c2f13459f4086a774285144btr2' || a == '43581c2f13459f4086a7742851444564') && (mjr == 'accepted')) {
if (al != '' && b != '')
g_form.setMandatory("u_alerting_comment", true);
if (b != '' && c != '')
g_form.setMandatory("u_awareness_comment", true);
if(c!='' && d!='')
g_form.setMandatory("u_escalate_comment", true);
}
}
I want the fields mentioned in this above code as mandatory once the fields are filled, but the script is working after saving the form.
Is there any other way to do this once the fields is populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 07:31 AM
Hi Brad,
function onLoad() {
//Type appropriate comment here, and begin script below
var a = g_form.getValue('assignment_group');
var mjr = g_form.getValue('major_incident_state');
var al = g_form.getValue('u_incident_started');
var b = g_form.getValue('u_alert_reported');
var c = g_form.getValue('u_on_call_notified');
var d = g_form.getValue('u_required_group_engaged');
var e = g_form.getValue('u_corrective_action_determined');
var f = g_form.getValue('u_system_at_a_useable_level);
var g = g_form.getValue('u_checkout_completed');
if ((a == 'xyz' || a == 'abc') && (mjr == 'accepted')) {
if (al != '' && b != '')
g_form.setMandatory("u_alerting_comment", true);
else
g_form.setMandatory("u_alerting_comment", false);
if (b != '' && c != '')
g_form.setMandatory("u_awareness_comment", true);
else
g_form.setMandatory("u_awareness_comment", false);
if (c != '' && d != '') {
g_form.setMandatory("u_escalation_comment", true);
g_form.setDisplay("u_escalation_comment", true);
} else {
g_form.setMandatory("u_escalation_comment", false);
g_form.setDisplay("u_escalation_comment", false);
}
if (d != '' && e != '')
g_form.setMandatory("u_triage_comment", true);
else
g_form.setMandatory("u_triage_comment", false);
if (e != '' && f != '')
g_form.setMandatory("u_remediation_comment", true);
else
g_form.setMandatory("u_remediation_comment", false);
if (f != '' && g != '')
g_form.setMandatory("u_checkout_comment", true);
else
g_form.setMandatory("u_checkout_comment", false);
}
The above code is the exact scenario, it is working after the form is saved but I need once the fields are populated (not empty) at the same time I want to make the field mandatory
eg:
ALERTING Comment field is required when:
Incident Started and Alert reported are populated.
but the onload client script is working after saving the form not before
I tried the same using on change client script but it is not working, I marked the field as empty in on change because the scenario is not based on one particular field changes.
Can anyone please help me on this.