
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 08:30 AM
HI,
I need to hilde some fields on a form view - dependend on values of the same table, but NOT visible on the current view.
I need to use a client script due to other reasons - so NO UI policy can be used - has to be via the client script.
When adding the fields on the form, it's working.
When removing them on the form - the check will not work anymore. So far I even can understand it.
So what I thought is to then just run a querry on the table to get the check fields ... but this seem not to work ... any idea?
To reproduce:
Table sys_user has a field CHECK (True/False).
On view "VIEW" of table sys_user the field "Field" should only be displayed if sys_user.CHECK is true ...
What i wrong with this client script?
function onLoad() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', sys_id); // current not to be used on onLoad CS
gr.query();
if(gr.next()) {
if (gr.CHECK != true ) { // if FIELD not TRUE
g_form.setDisplay('FIELD', false); // Hide FIELD
}
}
... as I said, if the field is added to the view, this works ... but I do not want it on the view
if (g_form.getValue('CHECK') != 'true' ) { // if not MDM User
g_form.setDisplay('FIELD', false); // Hide guideline smartphone
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 06:18 AM
Here is the sample script, Try this:
Client Script:
//Write this onLoad script on 'sys_user' table
function onLoad() {
var sys_id = g_form.getUniqueValue();
var ga = new GlideAjax('FieldDisplayUtil');
ga.addParam('sysparm_name','displayField');
ga.addParam('sysparm_sys_id',sys_id);
ga.getXMLWait();
if(ga.getAnswer() == 'true') {
g_form.setDisplay('FIELD', 'false');
}
}
Script Include:
//Client Callable should be checked and script include name should be "FieldDisplayUtil"
var FieldDisplayUtil = Class.create();
FieldDisplayUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
displayField: function(){
var answer = '';
var sys_id = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', sys_id);
gr.query();
if(gr.next()) {
if(gr.CHECK != 'true'){
answer = 'false';
return answer;
}
else{
answer = 'true';
return answer;
}
}
},
type: 'FieldDisplayUtil'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 08:36 AM
What is 'sys_id' in this field? Are you looking to get the record's sys_id that you are viewing?
If so, then put this before your query...
var sys_id = g_form.getUniqueValue();
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#getUniqueValue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 08:41 AM
Hi Chuck,
seems not to work.
I'm on a user record with a specific view ... and need to check the sys_user table of that user I'm currently watching for a specific field value (but this one is not on the current form view ...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 09:03 AM
If the field isn't on the form then you cannot use a client script or UI policy on it.
You CAN make client scripts run on a specific view by unchecking the Global field and setting the view name in the View field. (eg. ess)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 08:37 AM
You can't use GlideRecord in Client Scripting. Here you need to use Glide Ajax.
Also I was not able to understand what you are trying to do here. Can you please elaborate
Thanks,
Arindam