- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2015 01:11 AM
Need to personalize form layout for CI forms. Need to pull some fields and rearrange it for all the CI Class. The problem is we have more than 100 class in CI table. Need to open all the CI forms and changing it will be a tedious work. Is it any easy way to personalize form layout that will affect all the CI class globally.
Not by the normal way (Right clicking the form header and configure--> form layout and pull the fields from there should affect all the CI Class globally)
Thanks,
Alad.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2015 02:00 AM
Hi Anto,
I have converted above code to Script Include.
You need to call this script include from background script.
Script Include Name is 'u_CIFormUtil'. Script include function accepts 3 parameters. Source Class table name, Target class table name, and sys_ids of UI sections of target table which is to be made == to source table.
var u_CIFormUtil = Class.create();
u_CIFormUtil.prototype = {
initialize: function() {
},
//This script will add the fields to the default view of the extended table . You need to customize the default view of base table like 'cmdb_ci_server'
// Once you are done with adding all the fields on default view of the base table, run this script by passing sys_id of the 'sys_ui_section' of the extended table.
CIUICaption: function(sourceTable, targetTable, targetTableUISectionSysID){
var gr = new GlideRecord('sys_ui_element');
gr.addQuery('sys_ui_section.caption',''); //
gr.addQuery('sys_ui_section.name',sourceTable); // base class to query
gr.query();
while(gr.next())
{
gs.print('Element Name: ' + gr.element + ' ' + 'Position: ' + gr.position);
//gs.print(gr.sys_ui_section.name);
//gs.print(gr.sys_ui_section.view);
var count = 0;
var child = new GlideRecord('sys_ui_element');
child.addQuery('sys_ui_section.caption','');
child.addQuery('sys_ui_section.name',targetTable); // extended table fields check
child.addQuery('element',gr.element);
child.query();
while(child.next()) // if found then aling the position of the fields to that of base table
{
gs.print('old pos: ' + child.position + ' ' + child.element);
child.position = gr.position;
child.update();
//var UIsec = new GlideRecord('sys_ui_section');
//UIsec.get(child.sys_ui_section);
//UIsec.update();
gs.print('new pos child : ' + child.position + ' parent pos : ' + gr.position + ' ' + child.element + ' ' + gr.element);
count++;
}
if(count ==0) // if field (element) does not found on the default view, then add it. Also align the element position to that of element position of base table
{
var addChildField = new GlideRecord('sys_ui_element');
addChildField.initialize();
addChildField.sys_ui_section = targetTableUISectionSysID; // sys_id of the UI section of the extended table which is to make same as base table UI section
addChildField.element = gr.element;
addChildField.position = gr.position;
addChildField.type = gr.type;
addChildField.insert();
addChildField.sys_ui_section.update();
//var UIsec1 = new GlideRecord('sys_ui_section');
// UIsec1.get(addChildField.sys_ui_section);
//UIsec1.update();
//var updateView = addChildField.sys_ui_section.view.getRecord();
//updateView.update();
gs.print('Added fields' + addChildField.element + ' ' + addChildField.position);
}
}
},
type: 'u_CIFormUtil'
};
Below code you have to write down in script backgrounds
var sourceTableArray = ['cmdb_ci_server']; // all source tables can be listed in array
var targetTableArray = ['cmdb_ci_linux_server'];// all target tables can be listed here in array
var targetTableUISectionArray = ['5f815e5fc0a8010e009bab06a8515bc9']; // all sys_ids can be listed for UI section of target table
var obj = new u_CIFormUtil();
for(var j = 0 ; j < sourceTableArray.length; j++)
{
gs.print('in loop');
obj.CIUICaption(sourceTableArray[j] ,targetTableArray[j],targetTableUISectionArray[j]);
}
Also, to export all the tables UI sections sys_ids, you can put below URL in your browser.
https:// instaceName.service-now.com/sys_ui_section.do?CSV&sysparm_default_export_fields=all
Kindly test this in Demo or dev instance. This should work.
Kindly mark this as helpful / correct answer if you don't have any other follow up questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2015 05:07 AM
Hi Anto,
You will have to run this as a background script with elevated previledeges.
I would recommend to run it first on sandbox and check if everything is working for you as expected.
Once done, you can then convert this one into BR or Script Include etc, or can still run as background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2015 11:42 PM
Hello Deepak,
Was struggling to run the script. can you tell me if i run it as a BR, then which table to run this and what all changes need to be done in the code for me to work.
Thanks,
Alad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2015 02:02 AM
Hi Anto.
Kindly run this as background script by doing following things first
1) Open up any record of the cmdb_ci_server since code posted above will apply default view section of this class to cmdb_ci_win_server class.
2) add some fields to the default section on the form.
3)type sys_ui_section.list in navigation pane on left side. It will open up all the UI Sections for all the tables.
4)Filter the UI section where table name = cmdb_ci_win_server. Look for the UI section where 'caption' is blank or null . You will find 2 sections for this table OOB. One with caption name 'configuration' and other with blank. You have to open the one where caption name is blank.
5) copy the sys_id of this section. You will have to write it at the script line 32 in script posted above.
6)Once done, you will have to run above code via background script.
What it does?
1)You add fields on default view of the cmdb_ci_server. You want the same fields with same view to be aviable for cmdb_ci_win_server as well. This script will ensure to take care of this.
By using same principal, you can do it for other classes as well.
You use this as a model and can convert it to the BR as well. I haven't tried that with but. Even you can convert it to the SCript Include and call it as and when required.
I hope above explanation will now help you to go ahead with this script.
Let me know if you have any other questions as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2015 10:39 AM
its working fine, but the only thing is its not arranged in the correct place as it is in the cmdb_ci_server. Need to arrange everything once again one by one. Any solution for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2015 02:00 AM
Hi Anto,
I have converted above code to Script Include.
You need to call this script include from background script.
Script Include Name is 'u_CIFormUtil'. Script include function accepts 3 parameters. Source Class table name, Target class table name, and sys_ids of UI sections of target table which is to be made == to source table.
var u_CIFormUtil = Class.create();
u_CIFormUtil.prototype = {
initialize: function() {
},
//This script will add the fields to the default view of the extended table . You need to customize the default view of base table like 'cmdb_ci_server'
// Once you are done with adding all the fields on default view of the base table, run this script by passing sys_id of the 'sys_ui_section' of the extended table.
CIUICaption: function(sourceTable, targetTable, targetTableUISectionSysID){
var gr = new GlideRecord('sys_ui_element');
gr.addQuery('sys_ui_section.caption',''); //
gr.addQuery('sys_ui_section.name',sourceTable); // base class to query
gr.query();
while(gr.next())
{
gs.print('Element Name: ' + gr.element + ' ' + 'Position: ' + gr.position);
//gs.print(gr.sys_ui_section.name);
//gs.print(gr.sys_ui_section.view);
var count = 0;
var child = new GlideRecord('sys_ui_element');
child.addQuery('sys_ui_section.caption','');
child.addQuery('sys_ui_section.name',targetTable); // extended table fields check
child.addQuery('element',gr.element);
child.query();
while(child.next()) // if found then aling the position of the fields to that of base table
{
gs.print('old pos: ' + child.position + ' ' + child.element);
child.position = gr.position;
child.update();
//var UIsec = new GlideRecord('sys_ui_section');
//UIsec.get(child.sys_ui_section);
//UIsec.update();
gs.print('new pos child : ' + child.position + ' parent pos : ' + gr.position + ' ' + child.element + ' ' + gr.element);
count++;
}
if(count ==0) // if field (element) does not found on the default view, then add it. Also align the element position to that of element position of base table
{
var addChildField = new GlideRecord('sys_ui_element');
addChildField.initialize();
addChildField.sys_ui_section = targetTableUISectionSysID; // sys_id of the UI section of the extended table which is to make same as base table UI section
addChildField.element = gr.element;
addChildField.position = gr.position;
addChildField.type = gr.type;
addChildField.insert();
addChildField.sys_ui_section.update();
//var UIsec1 = new GlideRecord('sys_ui_section');
// UIsec1.get(addChildField.sys_ui_section);
//UIsec1.update();
//var updateView = addChildField.sys_ui_section.view.getRecord();
//updateView.update();
gs.print('Added fields' + addChildField.element + ' ' + addChildField.position);
}
}
},
type: 'u_CIFormUtil'
};
Below code you have to write down in script backgrounds
var sourceTableArray = ['cmdb_ci_server']; // all source tables can be listed in array
var targetTableArray = ['cmdb_ci_linux_server'];// all target tables can be listed here in array
var targetTableUISectionArray = ['5f815e5fc0a8010e009bab06a8515bc9']; // all sys_ids can be listed for UI section of target table
var obj = new u_CIFormUtil();
for(var j = 0 ; j < sourceTableArray.length; j++)
{
gs.print('in loop');
obj.CIUICaption(sourceTableArray[j] ,targetTableArray[j],targetTableUISectionArray[j]);
}
Also, to export all the tables UI sections sys_ids, you can put below URL in your browser.
https:// instaceName.service-now.com/sys_ui_section.do?CSV&sysparm_default_export_fields=all
Kindly test this in Demo or dev instance. This should work.
Kindly mark this as helpful / correct answer if you don't have any other follow up questions.