- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 03:41 AM
Hi,
I found an on load script to highlight fields which are recommended on a CI.
However the load script did not work and the user is no longer active on this forum.
Can anybody advise an issue in the script, or a way to highlight a recommended field on a CI form view.
Thanks
function onLoad() {
if(g_form.getTableName().indexOf('cmdb_ci')==0){
var gr = new GlideRecord('cmdb_recommended_fields');
gr.addQuery('active','true');
gr.addQuery('table',g_form.getTableName());
gr.query(displayResults);
}
function displayResults(response){
response.rows.forEach(function(thisRow){
thisRow.forEach(function(thisColumn){
if(thisColumn.name=='recommended'){
var thisField = jQuery('input[id="sys_display.'+g_form.getTableName()+'.'+thisColumn.value+'"]').length ==0 ? jQuery('input[id="'+g_form.getTableName()+'.'+thisColumn.value+'"]'): jQuery('input[id="sys_display.'+g_form.getTableName()+'.'+thisColumn.value+'"]');
thisField.css('background','lightyellow');
}
});
});
}
}
CI Class Manager - Recommended Fields - ServiceNow Community
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 06:21 AM - edited 09-25-2024 03:40 AM
Here is a slightly better way to do the same, at least eliminating the Client Script GlideRecord. This will work in the native UI.
function onLoad() {
var tableName = g_form.getTableName();
if (tableName.indexOf('cmdb_ci') == 0) {
var ga = new GlideAjax('CMDBUtils');
ga.addParam('sysparm_name','checkRecFields');
ga.addParam('sysparm_tablename',tableName);
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var thisColumn = answer.split(',');
for (i=0; i<thisColumn.length; i++) {
var thisField = jQuery('input[id="sys_display.'+tableName+'.'+thisColumn[i]+'"]').length ==0 ? jQuery('input[id="'+tableName+'.'+thisColumn[i]+'"]'): jQuery('input[id="sys_display.'+tableName+'.'+thisColumn[i]+'"]');
thisField.css('background','lightyellow');
}
}
}
The Script Include, with Client callable box checked:
var CMDBUtils = Class.create();
CMDBUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecFields: function() {
var answer = 'none';
var tablename = this.getParameter('sysparm_tablename');
var gr = new GlideRecord('cmdb_recommended_fields');
gr.addActiveQuery();
gr.addQuery('table', tablename);
gr.query();
if (gr.next()) {
answer = gr.recommended;
}
return answer;
},
type: 'CMDBUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 07:42 AM
HI @Brad Bowman ,
I'm trying to make this work in Washington realease but it doesn't. Any advise?
Thanks.
Elisa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 10:25 AM
Hi Elisa,
I was using Washington when I developed this, and it still works in my Xanadu release, so it shouldn't be a version issue. Are you using the native UI to view the CI? Are you certain that the Isolate script box is unchecked after saving the Client Script? You may need to add this field to your client script form. Does your configuration differ in any of the components from my screenshots?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 01:14 AM
Hi @Brad Bowman ,
I get this when configuring the client callable script include
Can this be the problem? How should I populate this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 04:32 AM
If you don't want the Script Include to be restricted, put the role snc_internal - or whatever role every user in your environment has.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 06:53 AM
All set! Thanks a lot Brad, much appreciated!