Removing or Disabling Choice on reference field

r_gissarl_
Mega Expert

Hi,

I have a service catalog form that is used by customers to fulfill change requests on users. In this form, 6 users field (reference) to select the users to apply the change. I wanted to disable the selected user on the first field in the other fields. For example, if Jon Doe is the first selected, he can't be selected on the other fields.

I found removeOption() (out-of-the-box) and disableOption (SN guru) solutions. But it seems to me that it only works on Choice lists and not on reference fields.

Is someone able to confirm this and may be help me in another solution ?

Best regards.

1 ACCEPTED SOLUTION

r_gissarl_
Mega Expert

Hi,



I finally have something right. I was not aware of reference qual so for all of you in my case, that's what I've done :



  1. On the reference variable (for memory, my variables are named user1, user2,... user6)
    1. set Use reference qualifier: Advanced
    2. set Reference qual: javascript:Except_these_users()
  2. Create a script include
    1. name : Except_these_users
    2. Script (and only the following) :

function Except_these_users() {


      //used for SIT-10 and SIT-07


      var j = 1;


      var anwser;


      var user_selected;


     


      answer = "sys_id!="


     


      while(j<7) {


              user_selected = current.variables['user'+ j];


              if (j<6) {


                      if (user_selected != '') {


                              answer += user_selected +'^sys_id!=';


                              //gs.log('Il y a ' + current.variables['user'+ j] + ' dans la liste ' + 'user'+j);


                      }


              }


              else {


                      if (user_selected != '') {


                              answer += user_selected;


                              //gs.log('Il y a ' + current.variables['user'+ j] + ' dans la liste ' + 'user'+j);


                      }


              }


              j++;


      }


      //gs.log('answer : ' + answer);


      return answer;


}



And it's working.


View solution in original post

4 REPLIES 4

Anurag Tiwari
Giga Contributor

you can user reference qualifier and pass on the variable value in it for validations.


something like this



if there are two fields,


field1 and field2



then in field2 reference qual you can add below filter script, if is about user table then



javascript:'user_name!='+current.variables.field1


Hello Anurag,



Well my reference fields are named : user1, user2, ... user6



When I use an advanced qual on user2, the selected user1 is still in the list :


javascript:'user_name!='+current.variables.user1


Probably, it's because it won't dynamically change when a user is set in user1.



So I put it in catalog script but it doesn't work either. Can you help me ?


i a number between 1 and 6 (for useri : user1, user2, etc.).



j = 1;

      var selected_user = g_form.getValue('user'+i);


      while(j<7) {


if (j!=i) {
//g_form.removeOption('user'+j, selected_user);
//disableOption('user'+j, newValue);
g_form.variables('user'+j).reference_qual = "javascript:'user_name!='+current.variables.user"+ i
alert('Retire ' + selected_user + ' de la liste ' + 'user'+j);
}
j++;

      }



r_gissarl_
Mega Expert

Hi,



I finally have something right. I was not aware of reference qual so for all of you in my case, that's what I've done :



  1. On the reference variable (for memory, my variables are named user1, user2,... user6)
    1. set Use reference qualifier: Advanced
    2. set Reference qual: javascript:Except_these_users()
  2. Create a script include
    1. name : Except_these_users
    2. Script (and only the following) :

function Except_these_users() {


      //used for SIT-10 and SIT-07


      var j = 1;


      var anwser;


      var user_selected;


     


      answer = "sys_id!="


     


      while(j<7) {


              user_selected = current.variables['user'+ j];


              if (j<6) {


                      if (user_selected != '') {


                              answer += user_selected +'^sys_id!=';


                              //gs.log('Il y a ' + current.variables['user'+ j] + ' dans la liste ' + 'user'+j);


                      }


              }


              else {


                      if (user_selected != '') {


                              answer += user_selected;


                              //gs.log('Il y a ' + current.variables['user'+ j] + ' dans la liste ' + 'user'+j);


                      }


              }


              j++;


      }


      //gs.log('answer : ' + answer);


      return answer;


}



And it's working.