Reference field UI Policy

kailashthiyagar
Kilo Guru
  • I have a UI policy for one of the reference field. If the value of the reference field is "Other", then show/hide another field. In the UI policy, by default it takes the SysID for the value "Other" rather than the value itself. So everytime, I reload the data , the SysID for the value "Other" is getting changed and the UI policy fails.

Can we force the reference field to take value rather than the sysID.. ?

There is no related fields appear for the particular column...

1 ACCEPTED SOLUTION

kailashthiyagarajan



Use GlideAjax. Here is the onload and onchange scripts and script include. In my case, if the watch list contains system administrator, show description field or else hide it. Make changes according to your fields and table.



onLoad:


function onLoad() {


  var ga = new GlideAjax('DisplayUtil');


  ga.addParam('sysparm_name','checkList');


  ga.addParam('sysparm_id',g_form.getValue('watch_list'));


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  g_form.setDisplay('description',true);


  }


  else{


  g_form.setDisplay('description',false);


  }


  }


}



onChange:


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


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


  return;


  }


  var ga = new GlideAjax('DisplayUtil');


  ga.addParam('sysparm_name','checkList');


  ga.addParam('sysparm_id',newValue);


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  g_form.setDisplay('description',true);


  }


  else{


  g_form.setDisplay('description',false);


  }


  }


  //Type appropriate comment here, and begin script below



}



Script Include:


Name:DisplayUtil


client callable:true


script:


var DisplayUtil = Class.create();


DisplayUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  checkList: function(){


  var gr= new GlideRecord('sys_user');


  gr.addQuery('sys_id','IN',this.getParameter('sysparm_id'));


  gr.query();


  while(gr.next()){


  if(gr.name=='System Administrator')


  return true;


  }


  return false;


  },


  type: 'DisplayUtil'


});


View solution in original post

20 REPLIES 20

kailashthiyagarajan


Use this in a client side code



if(g_form.getControl('<field name   goes here>').previousSibling.innerHTML.indexOf('Other')>-1){


g_form.setDisplay('field name',true);


}


else{


g_form.setDisplay('field name',false);


}


abhi_r


Thanks.. Should be adding both onChange and OnLoad.. Right?


Abhinay Erra
Giga Sage

Yes create both. You can also do both of them in a single onChange scrip too.


During OnChange, the below one



g_form.getControl('<field name   goes here>').previousSibling.innerHTML.



holds the current values only and not the newly selected value.



So the condition fails..


kailashthiyagarajan



Use GlideAjax. Here is the onload and onchange scripts and script include. In my case, if the watch list contains system administrator, show description field or else hide it. Make changes according to your fields and table.



onLoad:


function onLoad() {


  var ga = new GlideAjax('DisplayUtil');


  ga.addParam('sysparm_name','checkList');


  ga.addParam('sysparm_id',g_form.getValue('watch_list'));


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  g_form.setDisplay('description',true);


  }


  else{


  g_form.setDisplay('description',false);


  }


  }


}



onChange:


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


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


  return;


  }


  var ga = new GlideAjax('DisplayUtil');


  ga.addParam('sysparm_name','checkList');


  ga.addParam('sysparm_id',newValue);


  ga.getXML(CallBack);



  function CallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer=='true'){


  g_form.setDisplay('description',true);


  }


  else{


  g_form.setDisplay('description',false);


  }


  }


  //Type appropriate comment here, and begin script below



}



Script Include:


Name:DisplayUtil


client callable:true


script:


var DisplayUtil = Class.create();


DisplayUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  checkList: function(){


  var gr= new GlideRecord('sys_user');


  gr.addQuery('sys_id','IN',this.getParameter('sysparm_id'));


  gr.query();


  while(gr.next()){


  if(gr.name=='System Administrator')


  return true;


  }


  return false;


  },


  type: 'DisplayUtil'


});