Customize Form layout for CI Form

aladpereira
Mega Expert

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.

1 ACCEPTED SOLUTION

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.




View solution in original post

19 REPLIES 19

bernyalvarado
Mega Sage

One option that you have is to directly interact through script with the sys_ui_section table.



Thanks,


Berny


can you help me with any example, since i havnt done this before. Will this change affect for all users.



Regards,


Alad.


Hello Anto,


I have a script for it which i ll be sharing with you on tuesday if you still dont get tht one till tuesday.


is that possible to share a sample right now, since its very urgent, i m working on it right now