- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 10:06 AM
- 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...
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 01:26 PM
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'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 10:12 AM
What table is the field referencing? Why would the sys_id change every time? Because the other record in the reference table will have same sys_id all the time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 10:26 AM
I m using custom look up table. When i reload the data in the table its sysid changing. I think i should go for scripted UI policy as Slava mentioned

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 10:28 AM
Yes I will recommend using client script not a Ui policy so that it is more cleaner and easy to find. ANd use getDisplayBox() to get the display value of the reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 10:18 AM
One option is to use Client Script or a scripted UI Policy and check the display value of the reference field using getDisplayValue() method. Another possibility is to reconfigure you Transform Map so that the record named Other retains its sys_id when you re-load your data.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/