- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:24 AM - edited 02-02-2024 01:28 AM
Hi @kranthi2
Syntax is wrong
else
{
it will contain only action no valdiation
it will be like this
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:41 AM
Hello @kranthi2 ,
The else statement does not need a condition. It should be just else without a condition.
Try to use below code and adjust it further accordingly.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = g_form.getValue("u_sub_category");
var ca = g_form.getValue("u_category");
if (gr == '30f3911d8748ca50c02ecb790cbb3521') {
g_form.setValue("u_issue_type", "2772d9998748ca50c02ecb790cbb355b");
} else if (gr == '9cee089187c0ca50c02ecb790cbb35a1') {
// Add your logic for this condition if needed
// Example: g_form.setValue("u_issue_type", "your_value");
} else {
// Default case or add more conditions as needed
g_form.setValue("u_issue_type", "7b9fc0d187c0ca50c02ecb790cbb3536");
}
// Add more logic as needed below this point
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:24 AM - edited 02-02-2024 01:28 AM
Hi @kranthi2
Syntax is wrong
else
{
it will contain only action no valdiation
it will be like this
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:27 AM
You can't use a condition in else and need to use else if insted.
For example:
if(condition){
//Runs if first "if" condition triggers.
}else if(condition){
//This runs only if the previous "if" or "else if" don't trigger.
//You can have as many of these as you need.
}else{
//What happens when if and else if's don't trigger.
}
Also, don't use gr as the variable name for subcategory as that makes the script confusing since it's usually used for GlideRecord. Also best practice is to use variable names that make it clear what the variable holds. For example subCat might make more sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 01:41 AM
Hello @kranthi2 ,
The else statement does not need a condition. It should be just else without a condition.
Try to use below code and adjust it further accordingly.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = g_form.getValue("u_sub_category");
var ca = g_form.getValue("u_category");
if (gr == '30f3911d8748ca50c02ecb790cbb3521') {
g_form.setValue("u_issue_type", "2772d9998748ca50c02ecb790cbb355b");
} else if (gr == '9cee089187c0ca50c02ecb790cbb35a1') {
// Add your logic for this condition if needed
// Example: g_form.setValue("u_issue_type", "your_value");
} else {
// Default case or add more conditions as needed
g_form.setValue("u_issue_type", "7b9fc0d187c0ca50c02ecb790cbb3536");
}
// Add more logic as needed below this point
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket