- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:19 AM
Dear Community,
with the help of a fix script, I added a custom field 'u_prio_group' to the child tables of the 'cmdb_ci_service' table. Now the customer wants me to revert this, but as I'm quite new to coding (and the fix script was not written by someone else), I am not sure how to revert this, delete the field from all the child tables - and not mess this up.
Can anyone please tell me how to modify this fix script so it actually deletes that one element/field?
// Elements you want to add to every CI class
// (In list of objects for consistency with other CMDB Scripts)
// Note: these elements should exist on the base table already, to add new elements, please use one of the alternate scripts
var elements = [
{name:'u_prio_group'}
];
// The highest level parent table you wish to start decending downwards from
// eg. cmdb_ci / cmdb_ci_hardware
var baseTable = "cmdb_ci_service";
// Searches for every base table related UI Section that has no caption
var gr = new GlideRecord("sys_ui_section");
gr.addEncodedQuery("nameSTARTSWITH"+baseTable+"^captionISEMPTY");
gr.query();
// Itterate through each UI Section
// If the elements already exist, ignore them
// If not, create the new element and insert it with reference to the UI Section
while (gr.next()) {
for(var i = 0; i < elements.length; i++){
if(!exists(gr.sys_id,elements[i].name)){
var gr2 = new GlideRecord('sys_ui_element');
gr2.initialize();
gr2.element = elements[i].name;
gr2.sys_ui_section = gr.sys_id;
gr2.position = elementcount(gr.sys_id)+1;
gr2.insert();
gs.log("UI Element "+elements[i].name+" created on "+gr.sys_id);
}else{
gs.log("UI Element "+elements[i].name+" already exists on "+gr.sys_id);
}
}
}
gs.cacheFlush();
// Checks if the supplied element already exists for the UI Section
function exists(id,element){
var gr = new GlideRecord("sys_ui_element");
gr.addEncodedQuery("sys_ui_section="+id+"^element="+element);
gr.query();
if(gr.getRowCount() > 0){
return true;
}
return false;
}
// Returns the count of elements attached to the UI Section for positioning purposes
function elementcount(id){
var gr = new GlideRecord("sys_ui_element");
gr.addEncodedQuery("sys_ui_section="+id);
gr.query();
return gr.getRowCount();
}
Thank you so much in advance for any help..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:38 AM - edited ‎11-08-2022 08:39 AM
Test in sub-prod first, but you should be able to just delete all the dictionary entries/records for that field.
instanceName.service-now.com/sys_dictionary_list.do?sysparm_query=element%3Du_prio_group&sysparm_view=advanced
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:29 AM
Are you looking to delete the field completely or just remove it from all the forms?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:32 AM
Hello Mike,
I would like to remove it completely. And then add it the correct way through the CI Class Manager or via the Tables module to the 'cmdb_ci_service' table (where it does not appear now, which is wrong) and then have the field also visible on 'cmdb_ci_service_technical', 'cmdb_ci_service_business', and 'cmdb_ci_service_auto' child tables.
Unfortunately I only found out about these ways of adding fields to cmdb tables today..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:38 AM - edited ‎11-08-2022 08:39 AM
Test in sub-prod first, but you should be able to just delete all the dictionary entries/records for that field.
instanceName.service-now.com/sys_dictionary_list.do?sysparm_query=element%3Du_prio_group&sysparm_view=advanced
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 08:42 AM
hello,
Just wondering if the script is actually required why not just delete it from the dictionary itself?
Please mark my answer as correct based on Impact