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-23-2024 10:52 PM
same 3 onChange client scripts can handle all the combinations.
The above scripts are just for your reference. please enhance it further
I hope I answered your question.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 10:55 PM
here are the updated client scripts
Script 1: Q1 onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkConditions();
}
function checkConditions() {
var q1 = g_form.getValue('Q1');
var q2 = g_form.getValue('Q2');
var q3 = g_form.getValue('Q3');
if (q1 == 'Yes' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Private');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'Yes') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'No' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'Yes' && q2 == 'No' && q3 == 'Yes') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'No' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else {
g_form.clearValue('Q4');
}
}
Script 2: Q2 onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkConditions();
}
function checkConditions() {
var q1 = g_form.getValue('Q1');
var q2 = g_form.getValue('Q2');
var q3 = g_form.getValue('Q3');
if (q1 == 'Yes' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Private');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'Yes') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'No' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'Yes' && q2 == 'No' && q3 == 'Yes') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'No' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else {
g_form.clearValue('Q4');
}
}
Script 3: Q3 onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkConditions();
}
function checkConditions() {
var q1 = g_form.getValue('Q1');
var q2 = g_form.getValue('Q2');
var q3 = g_form.getValue('Q3');
if (q1 == 'Yes' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Private');
} else if (q1 == 'Yes' && q2 == 'Yes' && q3 == 'Yes') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'No' && q2 == 'No' && q3 == 'No') {
g_form.setValue('Q4', 'General');
} else if (q1 == 'Yes' && q2 == 'No' && q3 == 'Yes') {
g_form.setValue('Q4', 'Public');
} else if (q1 == 'No' && q2 == 'Yes' && q3 == 'No') {
g_form.setValue('Q4', 'Public');
} else {
g_form.clearValue('Q4');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 11:29 PM - edited 12-23-2024 11:41 PM
Hello Ankur,
Thank you for your reply.
Initially i have written first Catalog Client Script. How ever its not working.
Any Changes?
..........................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 11:40 PM
the script I shared should work fine.
Are you giving the correct choice value in the comparisons?
I could see in your below screenshot it did populate value as Regular for your combination
So it's working as expected
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 11:31 PM
I want like this