In an external assessment I want a submit button to be activated only if responded as 'Yes'

omsirsat
Kilo Contributor
In the Third Party Risk Management module, I have scenario for taking a acknowledgement from vendor. An external assessment is sent to the vendor. If vendor answers one of the question of acknowledgement as 'Yes' then only the submit button should be clickable, if answered as 'No' then the submit button should not be clickable (inactivated).
1 REPLY 1

Tanushree Maiti
Giga Patron

Hi @omsirsat 

 

I will suggest not to completely hide or deactivate the 'Submit' button (as this requires DOM manipulation which is not recommended as it often breaks during platform upgrades).

Instead, validate the form and prevent submission on the server side if the wrong answer is selected, accompanied by an explanatory error message

 

Option 1. Create an onChange Client Script:

    • Variable Name: Select your acknowledgement Yes/No variable. 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

    var ackQuestion = g_form.getValue('your_acknowledgement_variable_name');

    if (ackQuestion == 'No') {

        g_form.clearValue('your_acknowledgement_variable_name');

        g_form.showFieldMsg('your_acknowledgement_variable_name', 'You must acknowledge the terms by selecting Yes to proceed.', 'error');

    }

}

 

Option 2. Create an onSubmit Client Script:

    • Set the UI Type to All and check the Isolate script box to false.
    • Under the Type field, select onSubmit. 

 

function onSubmit() {

    var ackResponse = g_form.getValue('acknowledgement_question_var');     // Replace 'acknowledgement_question_var' with the actual Name

    if (ackResponse == 'No') {

        alert('You must answer "Yes" to the acknowledgement question in order to submit this assessment.');

        return false;

    }

}

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: