If Q1 is Yes and Q2 is No and Q3 is No then i need to display q4 with some value .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 09:56 PM
Hello Everyone,
If Q1 is Yes and Q2 is No and Q3 is No then i need to display q4 with some value . Like this i have 5-6 probability scenarios. i have used Client scripts. How ever few scenarios are not working and for few the Q4 value is not getting cleared. Can anyone help me on this?
Hopefully looking for possible solution, Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 12:56 AM - edited 12-24-2024 01:22 AM
Hello @irfan12
You will have to create 3 client script on each variable Q1, Q2, Q3.
onChange Client script for Q1, Q2, Q3 variable:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
// Get the values of q1, q2, q3
var q1 = g_form.getValue('q1') === 'yes';
var q2 = g_form.getValue('q2') === 'yes';
var q3 = g_form.getValue('q3') === 'yes';
// Initialize q4 value
var q4 = '';
// Condition 1: q1.(!q2) + (!q1).q2.(!q3)
if ((q1 && !q2) || (!q1 && q2 && !q3)) {
q4 = 'public';
}
// Condition 2: q1.q2.(!q3)
else if (q1 && q2 && !q3) {
q4 = 'private';
}
// Condition 3: q1.q2.q3 + (!q1).(!q2).(!q3)
else if ((q1 && q2 && q3) || (!q1 && !q2 && !q3)) {
q4 = 'general';
} else {
g_form.clearValue('q4');
}
// Set q4 field value
g_form.setValue('q4', q4);
}
Note: The client script will remain same for all the 3 variables.
I have simplified all the 6 condition and separated the condition for public, private, general.
The condition works in my PDI.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 01:52 AM
Hello @irfan12
Thank you for marking my response as helpful.
If this helped you to resolve the issue, can you please mark this as an accepted solution.
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 12:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 08:42 PM
Hi @irfan12 ,
You have to write three on change client script for Q1,Q2 and Q3.
Use same script in all three client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === oldValue) {
return;
}
var q1Value = g_form.getValue('q1');
var q2Value = g_form.getValue('q2');
var q3Value = g_form.getValue('q3');
// Scenario 1
if (q1Value == 'Yes' && q2Value == 'No' && q3Value == 'No') {
g_form.setValue('q4', 'Some Value'); // Set desired value for Q4
}
// Scenario 2
else if (q1Value == 'No' && q2Value == 'Yes' && q3Value == 'No') {
g_form.setValue('q4', 'Another Value');
}
/// Like wise you can create more scenarios.
// Default case: Clear Q4
else {
g_form.clearValue('q4');
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------