remove mandatory field messages on change form

pujitha K
Tera Contributor

Hi Team 

 

I have requirement that during change new state we have to make Risk assessment fields mandatory Risk Fields are customized field on change

 

We have written Ui policy to make the fields mandatory during new state.

 

Now everything is working as expected but now client want now to remove all mandatory Risk Assessment field messages on top of the form instead of that we need to have only one single message that "Risk Assessment is mandatory"

 

Is there any option that to remove oob functionality and add customized message 

pujithaK_1-1765810534545.png

 

Please check and help me to proceed further on the requirement.

 

Thanks,

Pujitha

 

5 REPLIES 5

Hemanth M1
Giga Sage

Hi @pujitha K ,

 

Instead of a UI policy, Can you write a client script(onSubmit) and check if these fields are empty if so throw a single error message "Risk Assessment is mandatory"

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Hi @Hemanth M1 ,

 

I have written client script(onSubmit) and tried but what it is happing is at the initial stage when we are just creating the change it will be in new state right at that time only these fields are mandatory and not allowing form to Submit.

 

My requirement is after initial change submission still change state will be in new right before going to another state it should not allow form submission and provide only one single message as "Risk assessment is mandatory.

 

Please help me out with the solution.

 

Thanks,

Pujitha

Hi @pujitha K ,

 

that's where you use "!g_form.isNewRecord()

you logic should be something like this 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (!g_form.isNewRecord() && g_form.getValue('state').toString() == '-5') {
        if (!g_form.getValue("Risk_field")) { //check if empty, update with your risk field
            alert("Risk info Mandatory");
            return false; //abort the submission
        }
    }
}
Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

 
I have tried the below code which is not working please correct me if i missing something's
 
function onSubmit() {
   
    if (!g_form.isNewRecord() && g_form.getValue('state').toString() == '-5') {


    var mandatoryFields = [

        'u_will_the_change_affect_any_business_critical_application_service_critical_site',
        'u_which_regions_are_impacted',
        'u_how_many_users_could_be_impacted_during_the_implementation_of_the_change',
        'u_how_difficult_it_is_to_roll_back_the_change_to_its_original_state',
        'u_has_testing_been_completed_for_this_chang',
        'u_is_downtime_required',
        'u_in_which_environment_will_this_change_be_implemented',
        'u_has_this_type_of_change_been_deployed_before_without_any_impact',
    ];
   
var missing = [];

for (var i = 0; i < mandatoryFields.length; i++){
    var fieldName = mandatoryFields[i];

    if (g_form.getValue(fieldName) == ''){

        missing.push(g_form.getLabelOf(fieldName));
        g_form.setMandatory(fieldName, true);

    }
}

if (missing.length > 0){

    alert('Risk Assesment is mandatory:\n\n' +missing.join(', '));
    return false;
}
    }
    return true;
}
Thanks,
Pujitha