List Collector On Change

Shalini Priya1
Tera Contributor

Hi ,

I have a requirement on List Collector (on Maintain Item), On selecting one of the option of the list collector , i want description field should be Mandatory.

  1. If the right collector list has Other option selected then the description field should become mandatory and if i remove the Other option from right collector then description should become optional.

find_real_file.png   find_real_file.png

2. And if i choose only Other , then Description field is becoming Mandatory but if i choose different options with Other and it is not working as below screen.In below case the description should be mandatory but its turning to optional.

find_real_file.png find_real_file.png

First scenario is working as expected but second scenario is not working.

Can anyone help me on this issue .

function onChange(control, oldValue, newValue, isLoading) {

  // if (isLoading || newValue == '' ) {

        // return;

  //}

var a1 = [];

var rightBucket = $('u_software_items_select_1');

var leftBucket = $('u_software_items_select_0');

for(i=0; i<rightBucket.options.length;i++){

  a1.push(rightBucket.options[i].text);

}

var j=0;

while(j<a1.length){

  if(a1[j]=='Other'){

  g_form.setMandatory('description',true);

  }

  else{

  g_form.setMandatory('description',false);

  }

  j++;

}

if(g_form.isMandatory('description') && rightBucket.options.length==0){

    g_form.setMandatory('description',false);

    }

}

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi Shalinipriya,



Please write an onChange catalog client script on change of the List Collector type field with the script below. I hope this will help you in your requirement:




function onChange(control, oldValue, newValue, isLoading) {


  if (newValue == '') {


  g_form.setMandatory('variable_name_of_Description', false);


  return;


  }



  if (isLoading || newValue != ''){


  if (newValue.toString().indexOf("8a590d024f65aa00a766a3b11310c777") >-1) { //pass the sys_id of the record 'Other'


  g_form.setMandatory('variable_name_of_Description', true);


  }


  else


  {


  g_form.setMandatory('variable_name_of_Description', false);


  }



  }


}




I hope this helps.Please mark correct/helpful based on impact


View solution in original post

3 REPLIES 3

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,



I guess your onChange script is on the list collector. What you can do is filter the "newValue" parameter you got. That is the result of the "right slushbucket". Only crappy part is that it is sys_id separated by semicolon. But you should look in newValue and see if you sys_id for other is there and then do you thing. Even if I isn't so happy to hardcode sys_ids



//Göran


amlanpal
Kilo Sage

Hi Shalinipriya,



Please write an onChange catalog client script on change of the List Collector type field with the script below. I hope this will help you in your requirement:




function onChange(control, oldValue, newValue, isLoading) {


  if (newValue == '') {


  g_form.setMandatory('variable_name_of_Description', false);


  return;


  }



  if (isLoading || newValue != ''){


  if (newValue.toString().indexOf("8a590d024f65aa00a766a3b11310c777") >-1) { //pass the sys_id of the record 'Other'


  g_form.setMandatory('variable_name_of_Description', true);


  }


  else


  {


  g_form.setMandatory('variable_name_of_Description', false);


  }



  }


}




I hope this helps.Please mark correct/helpful based on impact


Thanks Amlan.It worked.