Survey question mandatory on condition

sunilsargam
Kilo Sage

if survey question is 'are you satisfied or not satisfied' 

and if use select Not Satisfied - then  "Give additional info" question comes which is mandatory

 

I want to show this question even if satisfied but in this case, it should be non mandatory.

 

Is this feasible in servicenow surveys

5 REPLIES 5

Nilesh Pol
Kilo Sage

@sunilsargam Yes, this requirement is technically feasible in ServiceNow surveys, but it cannot be achieved solely through the standard "Depends on" functionality in the Survey Designer (which only supports hide/show, not dynamic mandatory settings).

You will need to use a Survey Client Script to dynamically change the mandatory state of the "Additional Info" field based on the "Satisfied" question answer.
Solution: Survey Client Script
Open Survey Designer: Go to Survey > View Surveys and open your survey.
Locate Metrics: Identify the Sys ID of both questions (the satisfaction question and the "Additional Info" question).
Add Client Script: Inside the Survey Designer, click the menu (three lines) in the top left, select Survey Client Script, and click New.
Configure Script:
Type: onChange
Question: Select your "Are you satisfied?" question.
Script: Use the following code (replace metric_sys_id with actual Sys IDs):

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}

// Replace these with the actual question (metric) sys_ids
var additionalInfoMetric = '00000000000000000000000000000000'; // SYSSID of "Give additional info"
var satisfiedQuestion = '11111111111111111111111111111111'; // SYSID of "Are you satisfied?"

// Get the value of the satisfaction question
var satisfactionValue = g_form.getValue(satisfiedQuestion);

// If 'Not Satisfied' (assume backend value is 'Not Satisfied')
if (satisfactionValue == 'Not Satisfied') {
g_form.setMandatory(additionalInfoMetric, true);
g_form.setVisible(additionalInfoMetric, true); // Show it
} else if (satisfactionValue == 'Satisfied') {
// If 'Satisfied', make it non-mandatory but still visible
g_form.setMandatory(additionalInfoMetric, false);
g_form.setVisible(additionalInfoMetric, true); // Show it
} else {
// Hide if no selection
g_form.setVisible(additionalInfoMetric, false);
g_form.setMandatory(additionalInfoMetric, false);
}
}

 

Alternative Approach (No-Code)
If you prefer not to use scripts, you can use the duplicate question method:
Create two "Additional Info" questions.
Question 1: Make it mandatory and "Depends on" = "Not Satisfied".
Question 2: Make it optional and "Depends on" = "Satisfied".
Note: This complicates reporting as you will have two different metric fields for the same data.

 

@Nilesh Pol 

It would be nice if you could share screenshots how that script is written, where etc it's written.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

iftekharmir
Tera Contributor

Hi @sunilsargam ,

 

Yes, this is feasible in ServiceNow surveys, and it can be handled using the configuration available on the survey question record (table: asmt_metric).

You can control both visibility and mandatory behavior using these fields:

Key fields to use

  • Displayed when → controls when the question is shown
  • Depends on → defines the parent question it relies on
  • Mandatory → controls whether the question is required

 How to achieve your requirement

  • Configure the “Give additional info” question to always be visible (or based on your condition using Displayed when)
  • Use Depends on to link it to the satisfaction question
  • Then control Mandatory based on the condition:
    • When answer = Not Satisfied → make it mandatory
    • When answer = Satisfied → keep it non-mandatory

Ankur Bawiskar
Tera Patron

@sunilsargam 

not possible to handle the mandatory logic dynamically

Only visibility can be controlled via "Depends on"

Workaround

-> create 2 identical questions

-> Q2 Depends on Question 1="Not Satisfied" and keep this Mandatory

-> Q3 Always visible (no dependency) and keep optional

Controlling Mandatory of Survey question based on other Survey question in same Survey 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader