- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 02:15 AM
Hi @Sagar Pagar
How to remove a particular dictionary attribute from all fields in table
I have already refereed bellow article it helped me some what so plss suggest
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0661882
Regards
Haresh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 10:49 AM
Hi @Haresh Haru,
Take a look at modified sample scripts. Try it and let me know.
var vTableName ="cmdb_ci_printer";// add table name here
var vAttribute = 'no_text_index=true';
var vDryRun = false; // set this to false when you're ready to do the change
var fieldsName = "name,first_name,last_name"; // add fields/columns name here
var array = fieldsName.toString().split(',');
bulkUpdateTableAttributes(vTableName, vAttribute, vDryRun);
function bulkUpdateTableAttributes(pTableName, pAttribute, pDryRun) {
var dictionaryObj = new GlideRecord('sys_dictionary');
dictionaryObj.addEncodedQuery('name=' + pTableName);
dictionaryObj.addQuery('element', 'IN', array);
dictionaryObj.query();
var bUpdate = false;
while (dictionaryObj.next()) {
var vAttributes = dictionaryObj.attributes.toString();
var nLength;
if (vAttributes) {
nLength = vAttributes.length;
} else {
nLength = 0;
}
if (0 == nLength) {
// There are no other attributes, just set it
// no need to update
} else {
// Attributes is not empty, check to see if we have it set already:
var indexNo = vAttributes.indexOf(pAttribute);
if (-1 == indexNo) {
// no need to update
} else {
// remove logic for given fields
var tempAttribute = pAttribute + ",";
var temp = vAttributes.replace(tempAttribute, "");
dictionaryObj.attributes = temp;
bUpdate = true;
}
if (!pDryRun) {
if (bUpdate) {
gs.print('Updating record sys_dictionary.do?sys_id=' + dictionaryObj.sys_id + ' to ' + dictionaryObj.attributes);
dictionaryObj.setWorkflow(false);
dictionaryObj.update();
}
}
bUpdate = false;
}
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 02:48 AM
Hi @Haresh Haru ,
The link for the article on your question covers what you want already.
As other way is time consuming, as you will need to do it one by one for each field :
right click on your field, then click configure dictionary, then , when form opens, click on advanced view. After this you will see your attributes is such a field (in the screenshot) - just remove yours and save:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 10:49 AM
Hi @Haresh Haru,
Take a look at modified sample scripts. Try it and let me know.
var vTableName ="cmdb_ci_printer";// add table name here
var vAttribute = 'no_text_index=true';
var vDryRun = false; // set this to false when you're ready to do the change
var fieldsName = "name,first_name,last_name"; // add fields/columns name here
var array = fieldsName.toString().split(',');
bulkUpdateTableAttributes(vTableName, vAttribute, vDryRun);
function bulkUpdateTableAttributes(pTableName, pAttribute, pDryRun) {
var dictionaryObj = new GlideRecord('sys_dictionary');
dictionaryObj.addEncodedQuery('name=' + pTableName);
dictionaryObj.addQuery('element', 'IN', array);
dictionaryObj.query();
var bUpdate = false;
while (dictionaryObj.next()) {
var vAttributes = dictionaryObj.attributes.toString();
var nLength;
if (vAttributes) {
nLength = vAttributes.length;
} else {
nLength = 0;
}
if (0 == nLength) {
// There are no other attributes, just set it
// no need to update
} else {
// Attributes is not empty, check to see if we have it set already:
var indexNo = vAttributes.indexOf(pAttribute);
if (-1 == indexNo) {
// no need to update
} else {
// remove logic for given fields
var tempAttribute = pAttribute + ",";
var temp = vAttributes.replace(tempAttribute, "");
dictionaryObj.attributes = temp;
bUpdate = true;
}
if (!pDryRun) {
if (bUpdate) {
gs.print('Updating record sys_dictionary.do?sys_id=' + dictionaryObj.sys_id + ' to ' + dictionaryObj.attributes);
dictionaryObj.setWorkflow(false);
dictionaryObj.update();
}
}
bUpdate = false;
}
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:02 AM - edited 03-09-2023 11:06 AM
Open list of this table - sys_schema_attribute_m2m_list
Then just use the filter - show related fields, choose dictionary entry, then again choose table. After this put your table name, then add AND condition for the attribute (or just right click and select show matching).
Then thats it in general 🙂
Hope this help man!