Make a variable not mandatory when a checkbox is marked

Kamva
Giga Guru

Hi Experts,

 

I have a requirement to make two variables inactive when a particular checkbox is marked. In achieving this requirement, I have developed a catalog client script. The problem I have is that the catalog client script is not triggering, please help me debbug. I got the configuration and the script below:

Configuration:

Kamva_0-1710844633584.png


Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    // Check the software_licensing field value
    if (g_form.getValue('software_licensing') == true) {
		alert('software_licensing == true');
        // Update mandatory property for hardware and select_request_type fields
        g_form.setMandatory('hardware', false);
        g_form.setMandatory('select_request_type', false);
    }
}


Regards,

Kamva

1 ACCEPTED SOLUTION

Community Alums
Not applicable

UI policy is the way to go.

 

 

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Kamva 

 

You want to make it ianctve or hide? If hide, better to use catalog UI policy which is low code ./ now code. 

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

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

Community Alums
Not applicable

UI policy is the way to go.

 

 

Rajesh Chopade1
Mega Sage

Hi @Kamva 

 

you need to modify your code:

if (g_form.getValue('software_licensing') == true) {

to 

if (g_form.getValue('variables.software_licensing') == true) {    

 

Also you need to keep in mind - 

Service portal not support to the variables.var_name

var usr = g_form.getValue('variables.requested_for');

The below onchange client script working fine for my requirement.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var user = newValue ; // using this i am able to get updated value in that field .

 

I hope my answer helps you to resolve your issue, please mark correct and helpful accordingly.

 

Thank you.

swathisarang98
Giga Sage
Giga Sage

Hi @Kamva ,

 

What exactly are you trying to achieve could you please share some screenshot ?

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang