Can some one will help on the below error message

kranthi2
Tera Expert

Hi,

Can some one will help on the below error message.

 

kranthi2_0-1706865684449.png

 

Thanks,

 

2 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @kranthi2 

 

Syntax is wrong

else

{

it will contain only action no valdiation

 

it will be like this

 

LearnNGrowAtul_0-1706865826796.png

 

*************************************************************************************************************
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]

****************************************************************************************************************

View solution in original post

Aniket Chavan
Tera Sage
Tera Sage

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


 

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @kranthi2 

 

Syntax is wrong

else

{

it will contain only action no valdiation

 

it will be like this

 

LearnNGrowAtul_0-1706865826796.png

 

*************************************************************************************************************
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]

****************************************************************************************************************

Weird
Mega Sage

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.

Aniket Chavan
Tera Sage
Tera Sage

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