Hiding a value from a reference field

ramak
Giga Expert

Is there a way of hiding a group name from "Assignment group" field on the Change form till the New Change reached "Scheduled" status ?

Reason for this is there is a group which only needs to be selected after all the approvals are done. This group in turn bridges with a 3rd party tool & selecting this group before the change is approved, would prematurely bridge the change request.

I know you can do this on a choice list but not sure on how to hide a value in a reference field.

Any input would help me here !!

1 ACCEPTED SOLUTION

Hi Suhas,



  1. No, you don't have to use a script include.   For an advanced refqual, you can specify "javascript:" with any valid javascript statments following it, including a call to a script include.   But you can also just insert your statements right there in the advanced refqual.   The advantage to calling a SI is that you could call a much more complex script... the refqual field does have a finite length which limits the amount of code you can enter there.
  2. If you want to list the 9 groups (out of 10) all the time, and include the 10th group when state=scheduled, use the second refqual I gave you (replace the group name and the state value with whatever you need):

            javascript:current.state==-15 ? "active=true":"active=true^name!=Infrastructure NSW";


One important thing to note, I see in your query you were using "nameNOTInfrastructure NSW", which I don't think is a valid query... which would explain why you are still seeing all of the groups.   An invalid query condition is ignored and all records are returned.



Instead you should be using "name!=Infrastructure NSW".




Try that and see how it works for you.




Thanks,


-Brian


View solution in original post

23 REPLIES 23

For advanced queries you need to create a script that outputs an encoded query string



Encoded Query Strings - ServiceNow Wiki



You can see what these look like by creating your desired condition in a list and then right clicking on the filter and clicking 'copy query'.



Lets say, If P1, only allow selection of group 'Incident Managers'


If any other Priority, exclude the group 'Incident Managers



RefQual.getGroupEncQuery = function(gr) {


var qry = [];


qry.push('active=true')


if (gr.priority ==1) {


qry.push('name=Incident Managers');


} else {


qry.push('name!=Incident Managers');


}


return qry.join('^');


}



P1 Output


active=true^name=Incident Managers



P2, P3, P4


active=true^name!=Incident Managers



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Oh still haven't used Encoded query strings, so not completely sure on how to use 'em.



Is there any particular syntax that I need to follow for using encoded strings ? (just need some info on how to start using this)


Hey Paul, I tried using the below method but still the group name is visible :



Advanced Reference qualifier : javascript:RefQuals.getGroupQuery(current);



Script Include :



var RefQuals = Class.create();



RefQual.getGroupEncQuery = function(gr) {  


var qry = [];  



if (gr.state == -15) {  


qry.push('nameISInfrastructure NSW');  


}


else


{  


qry.push('nameNOTInfrastructure NSW');  


}  


}   ;



RefQuals.prototype = {


      initialize: function() {


      },



      type: 'RefQuals'


};



Am I doing anything wrong here mate ?


You forgot to return anything!



var RefQuals = Class.create();


RefQual.getGroupEncQuery = function (gr) {


  var qry = [];


  if (gr.state == -15) {


  qry.push('nameISInfrastructure NSW');


  } else {


  qry.push('nameNOTInfrastructure NSW');


  }


  var encQry = qry.join('^');


  gs.print(encQry); //For debugging


  return encQry;


};




RefQuals.prototype = {


  initialize : function () {},




  type : 'RefQuals'


};



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Oops forgot to return...Thanks Paul, still ain't working



The reference qual am using is javascript:RefQual.getGroupEncQuery(current);



This is the script include below:



  1. var RefQual = Class.create();  
  2. RefQual.getGroupEncQuery = function (gr) {  
  3.   var qry = [];  
  4.   if (gr.state == -15) {  
  5.   qry.push('nameISInfrastructure NSW');  
  6.   } else {  
  7.   qry.push('nameNOTInfrastructure NSW');  
  8.   }  
  9.   var encQry = qry.join('^');  
  10.   gs.print(encQry); //For debugging  
  11.   return encQry;  
  12. };  
  13.  
  14.  
  15. RefQual.prototype = {  
  16.   initialize : function () {},  
  17.  
  18.  
  19.   type : 'RefQual'  
  20. };  


Renamed the script include to 'RefQual' also changed it in the ref qual. Anything that we are missing here mate ? (this might sound a bit silly to you but should we not declare 'gr' before we use it in the   getGroupEncQuery function?)





I am testing this by opening a new change request form & selecting the assignment group. The above group shouldn't be in the lookup as the state is not in 'scheduled'. But as of now still seeing the group name... HELP